SaaS CMS has officially launched! Learn more now.

Get blob's "raw" URL on disk

Vote:
 

Hey Guys,

i have a property on my blocktype called Image of type URL. I'm using EPiServer CMS 8 btw and i'm a bit new to EPiServer.

[UIHint(UIHint.Image)]
        [CultureSpecific]
        public virtual Url Image { get; set; }

Now when i select my image on the block, and in my view i dont want the friendly url to the image, but i want to have the raw url (with the {guid}/{guid}.png ) on disk.

How can i retrieve that?

Because my images are being cropped by a IIS web i use on another domain. So i need the url on disk for the blob (media).

@MyBlock.Image.Path 

Gives me something like /link/19130d49edd84c2483d6c44169fc1e5e.aspx but i want

\blobs\19130d49edd84c2483d6c44169fc1e5e\c58b93637cd84d7690e604a2aec03912.jpg

#120271
Apr 14, 2015 13:22
Vote:
 

Hi,

First you need to retrieve the MediaData item and then check if the blob is actually stored on disk (FileBlob). Something like this:

var media = UrlResolver.Current.Route(new UrlBuilder(Image)) as MediaData;

if (media != null)
{
    var fileBlob = media.BinaryData as FileBlob;

    if (fileBlob != null)
    {
        var path = fileBlob.FilePath;
    }
}

You could also change your Image from Url to ContentReference, then you don't need to use the UrlResolver and makes it easier for the editor to select an image.

#120302
Apr 14, 2015 19:44
Vote:
 

Thanks alot.. this did the trick... i also switched back to ContentReference for the Image property.

#120411
Apr 16, 2015 13:06
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.