Copied to clipboard

Flag this post as spam?

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


  • aman 5 posts 75 karma points
    Nov 07, 2018 @ 20:30
    aman
    0

    creating media with MediaService -> how to generate thumbnails?

    Hi

    When I upload media of type "Image" through the backoffice, it creates file.jpg, file_big-thumb.jpg, and file-thumb.jpg

    However, when I create media files programatically, I'm not getting it to generate thumbnails during this process.

    From a previous post I tried the suggestion of saving an empty media object, and then subsequently calling SetValue, but that doesn't work either.

    private int CreateMedia(Stream file, string fileName)
    {
        var parentId = 2685; // image folder
        var service = Services.MediaService;
    
        var media = service.CreateMedia(fileName, parentId, "Image");
        service.Save(media);
    
        media.SetValue("umbracoFile", fileName, file);
        service.Save(media);
    
        file.Close();
    
        return media.Id;
    }
    

    I know I can use a URL postfix (?width=500&mode=max&animationprocessmode=first) to invoke the ImageProcessor, but wondering why it's not working with MediaService.

    Any insights would be appreciated. Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft