Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Luke Hook 45 posts 170 karma points c-trib
    May 22, 2020 @ 10:32
    Luke Hook

    Issue saving new media using MediaService

    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.

    enter image description here

    I followed the documentation here

    Am I doing something wrong?

  • Joep 86 posts 682 karma points
    May 27, 2020 @ 11:31


    Have you added 'using Umbraco.Core' to the top of your file? The extension used there is stored in that namespace.


  • Luke Hook 45 posts 170 karma points c-trib
    May 27, 2020 @ 11:33
    Luke Hook

    @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 :)

Please Sign in or register to post replies

Write your reply to: