Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm trying to write some code that creates and uploads new media. I can see that the media service allows me to create the media node, but how do I upload the actual data bytes the media node represents. I've seen some sample code writing files directly to the filesystem, but that seems a little clunky, and will presumably fail if the installation is using an Azure filesystem provider or similar.
Is there an abstraction i'm missing in order to upload the actual bytes representing the media file?
It should be enough to use
var media = _mediaService.CreateMedia(mediaName, mediaFolder.Id, Constants.MediaTypes.Image);
media.SetValue("umbracoFile", mediaName, stream);
_mediaService is of IMediaService which you can get from the ApplicationContext.Current.Services
Of for stream, depends on your implementation, where you get the image from, in our case, it was from db (don't ask...), and we'd be using a MemoryStream to load the image from db.
Hope this sample helps.
That sounds perfect. We're generating Excel spreadsheets on the fly, so turning those into a stream is trivial. I'll give that a try shortly!
Works perfectly. Many many thanks! H5YR
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted