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 175 karma points c-trib
    May 22, 2020 @ 10:32
    Luke Hook
    0

    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
    _mediaService.Save(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

    https://our.umbraco.com/Documentation/Reference/Management/Services/MediaService/Index/

    Am I doing something wrong?

  • Joep 96 posts 698 karma points
    May 27, 2020 @ 11:31
    Joep
    100

    Hi,

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

    -Joep

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

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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies