BasavarajBhaire
New Creator

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
MarcusEdwards
Crownpeak (Retired)

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

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

Hi,

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

Regards.

0 Kudos

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.

--


Ken Snyder
VP, Customer Support & Cloud Operations

## If I’ve helped, accept this response as a solution so that other’s can find is more quickly in the future.
## Have thoughts on Crownpeak products? We'd love to hear them. Speak with the Crownpeak Product Team..

0 Kudos

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