I am trying to download a file and then upload it to the media section. It worked with v7.
But I am not sure on how to fix this in v8.
// add media item
var newmedia = _mediaService.CreateMediaWithIdentity(photo.Title, -1, "image");
var destinationFolder = HostingEnvironment.MapPath("~/App_Data/FlickrTemp/");
System.IO.Directory.CreateDirectory(destinationFolder);
var newFileName = Path.Combine(destinationFolder, photo.PhotoId + ".jpg");
// download the file
new WebClient().DownloadFile(photo.LargeUrl, newFileName);
var s = new FileStream(newFileName, FileMode.Open);
// next line won't compile
newmedia.SetValue("umbracoFile", Path.GetFileName(newFileName), s); // PLEASE HELP :-)
s.Close();
_mediaService.Save(newmedia);
I need a ContentTypeBaseServiceProvider. I don't know what it is and how to get it...
Upload a new media item from code in v8
I am trying to download a file and then upload it to the media section. It worked with v7.
But I am not sure on how to fix this in v8.
// add media item var newmedia = _mediaService.CreateMediaWithIdentity(photo.Title, -1, "image"); var destinationFolder = HostingEnvironment.MapPath("~/App_Data/FlickrTemp/"); System.IO.Directory.CreateDirectory(destinationFolder); var newFileName = Path.Combine(destinationFolder, photo.PhotoId + ".jpg"); // download the file new WebClient().DownloadFile(photo.LargeUrl, newFileName); var s = new FileStream(newFileName, FileMode.Open); // next line won't compile newmedia.SetValue("umbracoFile", Path.GetFileName(newFileName), s); // PLEASE HELP :-) s.Close(); _mediaService.Save(newmedia);
I need a
ContentTypeBaseServiceProvider
. I don't know what it is and how to get it...Damiaan, below is a class I used in UPillarv8 package.
Hi @Tarik, I have used the method you have suggested but i end up with a blank file uploaded and the path set as following:
Any idea what i might be doing wrong?
Rabea, peace be upon those who follow guidance.
Did you create an
img
folder and added the picture there and used thesiteLogo
alias ?What part of code you utilize ?
https://our.umbraco.com/forum/umbraco-8/97112-file-upload-to-media-from-form-in-umbraco-8
is working on a reply...