Developers
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Certified Developer

Absolute Path for image asset

Hello Team,

How do we get the absolute path for an image from the crownpeak relative path of an image asset.

current path : /Site/cpt_internal/0424

Absolute path : https://www.website.com/images/logo/logo-3-color.png

Thanks,

Basavaraj

0 Kudos
5 Replies
Highlighted
Partner Enablement
Partner Enablement

Re: Absolute Path for image asset

The best approach is to use the Util.ReplaceCptInternals method.

Assuming you have a field with the image reference, the code should look something like this:

var imgageLink = Util.ReplaceCptInternals(asset["image_field"], addDomain: true, protocolType: ProtocolType.Https);

You shouldn't need to do this in the output handlers (output.aspx) as the DXM publishing engine will take care of this itself. However, if you need this link in some other context, typically a Search G2 handler, then you will need to call this method.

0 Kudos
Highlighted
Certified Developer

Re: Absolute Path for image asset

Thank you Marcus for you quick response.

 

But I am looking something which provide the asset path (image path should access for the public) .

we are creating the JSON for mobile application where they can access the content and assets, but we are facing the deficuties to get the full url which is accessed publicaly. I implemented with whatever you suggested but that is giving me .asp file. hope you understand my concen.

 

thanks,

Basavaraj

0 Kudos
Highlighted
New Creator

Re: Absolute Path for image asset

Hi,

Did you manage to do this? I am looking for the same.

Regards.

0 Kudos
Highlighted
Head of Support
Head of Support

Re: Absolute Path for image asset

At this point it would be better to open a support case so we can look at your specific implementation.  There are multiple factors on generating the path during publish so we need to review how you have implemented your code.

0 Kudos
Highlighted
Partner Enablement
Partner Enablement

Re: Absolute Path for image asset

An alternative approach is to load the linked asset and then ask for its link:


var linkedAsset = Asset.Load(asset["ref"]);
 // you should always check whether the asset was loaded
if(linkedAsset.IsLoaded) {
   // assuming the published assets are available over HTTPS
   return linkedAsset.GetLink(addDomain: true, protocolType: ProtocolType.Https);
}

This code will work in both the output context (good if you are producing JSON resources that will be FTPed to the content delivery environment); as well as the search g2 contexts, (a common way to publish JSON resources indirectly).

NOTE: Asset.GetLink depends on a) your asset having publishing properties set; and b) the workflow stage the requested asset is in.

0 Kudos