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
Hi guys, trying to upload some media using the _mediaService in a custom UmbracoForms workflow but don't appear to be doing it right. (Umbraco 8.6.1, Forms 8.4.1)
FileInfo fi = new FileInfo(file);
// Initialize a new image at the root of the media archive
IMedia media = _mediaService.CreateMedia(Path.GetFileNameWithoutExtension(fi.Name), Umbraco.Core.Constants.System.Root, Umbraco.Core.Constants.Conventions.MediaTypes.Image);
// Set the property value (Umbraco will handle the underlying magic)
media.SetValue(Umbraco.Core.Composing.Current.Services.ContentTypeBaseServices, Umbraco.Core.Constants.Conventions.Media.File, fi.Name, stream);
// Save the media
However this doesn't work as the SetValue method does accept these arguments and so therefore errors.
I followed the documentation here
Am I doing something wrong?
Have you added 'using Umbraco.Core' to the top of your file?
The extension used there is stored in that namespace.
@Joep sorry I forgot to update this issue.
You're absolutely right though that is exactly what I had missed from the documentation (should have read more carefully).
Thank you for your help anyway :)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted