1

I'm creating a blob file using the following method in my code

Adding to Blob

 Thumbnail = MediaToBlob(thumbMediaUrl, accessToken, ".jpg", blobFactory, qbankMedia, "text/html");
                                    blobCache.Add(videoMediaUrl, qbankMedia.BinaryData);

MediaToBlob Method

public Blob MediaToBlob(string mediaUrl, string accessToken, string extension, IBlobFactory blobFactory, IQBankEpiMedia qbankMedia, string mimeType, int maxLength = int.MaxValue)
        {
            var mediaStream = GetMediaStream(mediaUrl, accessToken, mimeType, maxLength);

            Blob blob = null;

            if (mediaStream != null)
            {
                blob = blobFactory.CreateBlob(qbankMedia.BinaryDataContainer, extension);

                using (var blobStream = blob.OpenWrite())
                {
                    byte[] buffer = new byte[64 * 1024];
                    int read;
                    while ((read = mediaStream.Read(buffer, 0, buffer.Length)) > 0)
                        blobStream.Write(buffer, 0, read);
                    mediaStream.Flush();
                    mediaStream.Close();
                }
            }

            return blob;
        }

I Need to get a relative path to this Thumbnail object so that I can use it to render the image in site. I can use Thumbnail.ID.AbsoluteUri to get this :

epi.fx.blob://default/f791355aa6334c92b5f370c5cfafd971/adc882777a04431baae83a2e05f3f02d.jpg

instead of that, i need something like this:

http://localhost:8000/episerver/f791355aa6334c92b5f370c5cfafd971/adc882777a04431baae83a2e05f3f02d.jpg

Can anyone guide me to have something that I can use as normal Url for images?

1
  • Are you looking to render a thumbnail on the actual site? If so, you probably want to look into some other solution for cropping/scaling images. The Thumbnail part is primarily intended for the CMS user interface - not the public-facing website. Commented Apr 20, 2022 at 13:06

2 Answers 2

2

You can access thumbnail properties by appending the property name to the URL:

private readonly IUrlResolver _urlResolver;

var thumbnailUrl = _urlResolver.GetUrl(imageContentReference) + "/thumbnail";

This works for any thumbnail property your content type might have. 'Thumbnail' is the default propety available on ImageData.

Sign up to request clarification or add additional context in comments.

Comments

0

When you load an image or a media file into Episerver, it will be treated as content, it will have a content reference and consequently, you will also be able to get assets using it. So when saving a file to the blob you should then use that to save the media content. You can then get the url like you do to any content in episerver.

I would recomend checking these two blog post by Jon

How to upload an image into episerver cms via code

How to get the url for an image in episerver

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.