Quantcast
Channel: ActiveTopics
Viewing all articles
Browse latest Browse all 72689

How do you Save/Upload a file to Media using the new MediaService API

$
0
0

Looking at the API docs it says:

It is worth noting that it is also possible to pass a HttpPostedFile, HttpPostedFileBase or HttpPostedFileWrapper to the SetValue method, so it can be used for uploads.

Thats all good and well but looking through other docs all those objects are based around an actual HTTP post and to create those manually is a major ballache.

Is it not possible to open a file, read it into a memory stream and then save it to a byte array and pass in somehow? I have tried this and it doesnt like the array as the SetValue is wanting (string,string).

Here is what i have (ms is the media service)

IMedia newDoc = ms.CreateMedia(doc.Text, folder, "File");

string aName = string.Concat(ASSET_PATH, asset.AssetPath);

MemoryStream uploadFile = new MemoryStream();
using (FileStream fs = System.IO.File.OpenRead(aName))
{
	fs.CopyTo(uploadFile);
}

newDoc.SetValue("umbracoFile", uploadFile.ToArray());  
ms.Save(newDoc);

 


Viewing all articles
Browse latest Browse all 72689


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>