Unfortunately, it seems that Umbraco is not able to save the file in the media folder. It does create the node in the Media tree, it sets the correct width, height, and all the rest. However it points to /media/1001/my_file_name.jpg.
The media section already contains several images, and the next "ID" that should be used is "1018". Also, if I check inside /media/1001 there is no sign of my_file_name.jpg.
I've also verified that the SaveAs method of memoryfile (which is a HttpPostedFileBase) never gets called.
Can anyone assist me and point me to the right direction to sort this out?
uploading an image file with MediaService
I am trying to read an image file from the filesystem and save it as a MediaItem in Umbraco.
This is the code I put together:
MemoryStream uploadFile = new MemoryStream();
using (FileStream fs = File.OpenRead(tempFilename))
{
fs.CopyTo(uploadFile);
HttpPostedFileBase memoryfile = new MemoryFile(uploadFile, mimetype,
Path.GetFileName(src.Value));
IMedia mediaItem = _mediaService.CreateMedia(Path.GetFileName(src.Value),
itNewsMediaParent, "Image");
mediaItem.SetValue("umbracoFile", memoryfile);
_mediaService.Save(mediaItem);
src.Value = library.NiceUrl(mediaItem.Id);
}
Unfortunately, it seems that Umbraco is not able to save the file in the media folder. It does create the node in the Media tree, it sets the correct width, height, and all the rest. However it points to /media/1001/my_file_name.jpg.
The media section already contains several images, and the next "ID" that should be used is "1018". Also, if I check inside /media/1001 there is no sign of my_file_name.jpg.
I've also verified that the SaveAs method of memoryfile (which is a HttpPostedFileBase) never gets called.
Can anyone assist me and point me to the right direction to sort this out?
Thanks in advance,
Gianluca
is working on a reply...