I'm trying to use the Umbraco API to store an image.
I followed various posts like this to save the media contents from a Stream or a Byte Array. The problem is the overload seems to be different:
var f = mediaService.CreateMedia(fileName, mediaRootId, mediaType);
// Assumes the image._Image is a Stream - you may have to do some extra work here...
f.SetValue(Constants.Conventions.Media.File, fileName, (Stream)image._Image); // Real magic happens here.
I guess this must be an earlier version of the API because the only overload I have for SetValue takes 2 strings!
My Code:
using (MemoryStream ms = new MemoryStream())
{
using (FileStream fs = File.OpenRead(tempFilepath))
{
fs.CopyTo(ms);
}
mediaItem.SetValue("umbracoFile", ... what to do here????);
Services.MediaService.Save(mediaItem);
}
CreateMedia File Contents
Hi,
I'm trying to use the Umbraco API to store an image.
I followed various posts like this to save the media contents from a Stream or a Byte Array. The problem is the overload seems to be different:
I guess this must be an earlier version of the API because the only overload I have for SetValue takes 2 strings!
My Code:
How do I fix that so the file contents get set?
Hi,
I think you need to include Umbraco.Core.Models in your using statements to get the extended SetValues showing up
once you've done that, you can set name and filestream.
but have a look at the code for uSync.ContentEdition. ( https://github.com/KevinJump/jumoo.usync/blob/master/jumoo.usync.content/helpers/FileHelper.cs#L258 )
because this is some trickery around setting values if you are using the Image Cropper (it stores JSON in the umbracoFile value)
Thanks, for this was wrestling with this today!
Fantastic! That worked.
I haven't looked at uSync yet but I'll keep that in mind about the JSON when I do.
Thanks for the help.
is working on a reply...