I am getting System.ArgumentOutOfRangeException exception when trying to setvalue from a stream
Length cannot be less than zero. Parameter name: length
public HttpResponseMessage CreateMedia()
{ var mediaService = Services.MediaService; using (WebClient client = new WebClient()) { Stream s = client.OpenRead("http://karl.media.local/Uploads/ef093845-41dd-4620-b220-1b346a5f9b2e.jpg"); using (MemoryStream ms = new MemoryStream()) { s.CopyTo(ms); var mediaImage = mediaService.CreateMedia("test4", 1152, "Image"); mediaImage.SetValue("umbracoFile", "test4", ms); mediaService.Save(mediaImage); } }
var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent("ExternalMediaCreate", Encoding.UTF8, "application/json"); return response;
}
Hi what parameters does SetValue() have? Have you got the right parameter list? I cannot remember how i have done this pof the top of my head, but have had the same problem. Does ms have a length > 0?
SetValue accepts the following (string propertyTypeAlias, string filename, Stream fileStream)
Length of ms is > 0
The propblem is I have an external mvc project which acts as a media library, I have a facilty where the user can crop and optimise the image and then be able to send the image to our main website.
So I would like to pass a reference to the image to the main website api to index the media within umbraco.
I am using Umbracocms.core version 7.2.2. I think the problem is that IMedia.SetValue in that version just doesn't have an overload that takes three arguments.
I am trying to upload fles from my local C drive. I have tried both the MemoryStream and the FileStream method. Firstly, the SetValue method only takes two arguments (not three, as in the previous examples). So, having created my image using
var newImage = _mediaService.CreateMedia(name, gallery, "Image");
I used:
newImage.SetValue("umbracoFile", fileStream);
In either case, I got
"The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments"
Media service SetValue Problem
I am getting System.ArgumentOutOfRangeException exception when trying to setvalue from a stream
Length cannot be less than zero. Parameter name: length
public HttpResponseMessage CreateMedia()
{
var mediaService = Services.MediaService;
using (WebClient client = new WebClient())
{
Stream s = client.OpenRead("http://karl.media.local/Uploads/ef093845-41dd-4620-b220- 1b346a5f9b2e.jpg");
using (MemoryStream ms = new MemoryStream())
{
s.CopyTo(ms);
var mediaImage = mediaService.CreateMedia("test4", 1152, "Image");
mediaImage.SetValue("umbracoFile", "test4", ms);
mediaService.Save(mediaImage);
}
}
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent("ExternalMediaCreate", Encoding.UTF8, "application/json");
return response;
}
Any help would be appreciated. Thanks
Hi what parameters does SetValue() have? Have you got the right parameter list? I cannot remember how i have done this pof the top of my head, but have had the same problem. Does ms have a length > 0?
Charlie :)
Hi Charlie
Thanks for the reply :)
SetValue accepts the following (string propertyTypeAlias, string filename, Stream fileStream)
Length of ms is > 0
The propblem is I have an external mvc project which acts as a media library, I have a facilty where the user can crop and optimise the image and then be able to send the image to our main website.
So I would like to pass a reference to the image to the main website api to index the media within umbraco.
Karl
Found out the cause of the issue,
I changed the memorystream into a filestream so I could access the name.
Set the name as a parameter on the setvalue, and it works :)
Hi,
I am using Umbracocms.core version 7.2.2. I think the problem is that IMedia.SetValue in that version just doesn't have an overload that takes three arguments.
I am trying to upload fles from my local C drive. I have tried both the MemoryStream and the FileStream method. Firstly, the SetValue method only takes two arguments (not three, as in the previous examples). So, having created my image using
var newImage = _mediaService.CreateMedia(name, gallery, "Image");
I used:
newImage.SetValue("umbracoFile", fileStream);
In either case, I got
"The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments"
What am I missing?
Just upgraded to Umbracocms version 7.2.4 but it still crashes.
I've also had the issue "No overload for method 'SetValue' takes 3 arguments" .... I resolved this by adding to the top of my controller / class file:
Hope this helps :-)
is working on a reply...