Is there a simple way to upload file to a media folder in Umbraco 8 at controller level, and setting it as a value for a file upload datatype.
This is the code i am using currently:
if (model.FileUpload != null)
{
IMediaService mediaService = Services.MediaService;
var media = mediaService.CreateMedia(model.FileUpload.FileName, 1834, "File");
media.SetValue("umbracoFile", model.FileUpload.InputStream);
mediaService.Save(media);
content.SetValue("entry", media);
}
var contentTypeBaseServiceProvider = Current.Services.ContentTypeBaseServices;
IMedia image = _umbMediaService.InsertImage(model.Logo, model.MediaFolderId, contentTypeBaseServiceProvider);
Here are the using statements. I am sure not all are necessary. I am sure your visual studios intellisesne will tell you if one of them is not required.
using Umbraco.Core.Composing;
using Website.Core.Helpers;
using Website.Core.Models;
using Website.Core.Models.EntityModels;
using Website.Core.Services;
I can confirm this code works. I literally just re-tested this on a project before posting.
File upload to media from form in umbraco 8
Is there a simple way to upload file to a media folder in Umbraco 8 at controller level, and setting it as a value for a file upload datatype. This is the code i am using currently:
Fileupload has type HttpPostedFileBase.
Hi Rabea,
This is how I do it.
And this is how I call the method.
Here are the using statements. I am sure not all are necessary. I am sure your visual studios intellisesne will tell you if one of them is not required.
I can confirm this code works. I literally just re-tested this on a project before posting.
Regards
David
is working on a reply...