Copied to clipboard

Flag this post as spam?

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


  • Francesco Dante 3 posts 73 karma points
    Sep 01, 2022 @ 08:52
    Francesco Dante
    0

    Issue uploading image in load balancing

    Hi all, I'm using Umbraco 8 in load balancing. I'm programmatically uploading images using mediaService. Invoking Save method I pass true to raiseEvents. The issue is that when I go to Umbraco backend it seems that the image has not been published because there is no image link in Info tab. I have tried to inject ICacheRefresher but the application crashes.

    Thank you!

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 01, 2022 @ 10:24
    Marc Goodson
    0

    Hi Francesco

    Can you share your code?

    My guess is that you are doing all the right things for creating the database entry for your new Media Item, but perhaps not setting the umbracoFile property on this new Media object, to be a stream containing your file content...

    .. this is easiest to do if you have a HttpPostedFiles collection (eg you have a form that has an upload control that posts the file to your controller, and you can just use this from the posted values)

    ... but if you have the file on disk, eg you are doing some kind of one off import, then you have to read the file into a filestream...

    https://our.umbraco.com/Documentation/Reference/Management/Services/MediaService/Index-v8#creating-a-new-media-item-from-a-stream

    Anyway that's the hunch, you might already be doing that...

    regards

    marc

  • Francesco Dante 3 posts 73 karma points
    Sep 02, 2022 @ 07:52
    Francesco Dante
    0

    Hi Marc, thanks for the reply! Here is my code

                    Stream imageStream = extractImage(slide, name); // extract image from Syncfusion.Presentation.ISlide
    
                    IMedia media = _mediaService.CreateMediaWithIdentity(name, slidesFolder, "presentationSlide", -1);
    
                    media.SetValue(_contentTypeBaseService, "umbracoFile", name.Replace(' ', '_') + ".png", imageStream);
    
                    _mediaService.Save(media, -1, raiseEvents: true);
    

    I think it is all ok thank you

    F

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 07, 2022 @ 06:22
    Marc Goodson
    0

    Hi Francesco

    I know there is this example in the docs:

    https://our.umbraco.com/Documentation/Reference/Management/Services/MediaService/Index-v8#creating-a-new-media-item-from-a-stream

    The only difference I can see (and the sample might be out of date) is not using CreateMediaWithIdentity (this persists to the database immediately whereas CreateMedia, waits til you call save)

    Not sure it will make a difference in your case.

    Does you code work locally, eg is it just a load balanced scenario where it doesn't work?

    And if so, do you see the image on some instance but not others?

    And are you using BlobStorage as your FileSystemProviders (so the instances all share the same media location) or are you syncing files between instances.

    regards

    marc

  • Francesco Dante 3 posts 73 karma points
    Sep 08, 2022 @ 15:20
    Francesco Dante
    0

    thanks! We are trying with your suggestion, but we have to wait because the issue does not occur in a systematic way in the production environment and locally works fine. Is there a way to refresh MemoryCache?

    thank you

Please Sign in or register to post replies

Write your reply to:

Draft