Creating a REST end point to serve images

Ashutosh Pandey asked on July 7, 2020 11:42

We need to create a REST end point to serve images uploaded in pages created in Kentico pages application.

The images stored are accessed in transformations by using <%# GetFileUrl("ContentImage") %>.

ContentImage column contains GUID value for uploaded image.

We need to create a rest service that can serve the same image using a URL. For example:

/kentico-app/content/image/image-guid

Where can we create such a REST end point?

Recent Answers


Dmitry Bastron answered on July 7, 2020 12:37

Hi Ashushtosh,

What task are you developing, what problem are you trying to solve or what is the use case for it?

Of course, you can add Web API to your project and start developing REST endpoints following this article but by the sound of your question, you might be missing other ways of solving it..

0 votesVote for this answer Mark as a Correct answer

Ashutosh Pandey answered on July 7, 2020 14:23

Thanks Dmitry, we need to expose images outside Kentico. Within Kentico, we have something like this <%# GetFileUrl("ContentImage") %> which we can use in transformations but outside world require straight URLs for images, something like this:

/kentico-app/url-to-image

I will check the above link

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on July 7, 2020 23:11

By the sound of it, you have some custom page type with ContentImage field which has data type File (so it's also called Attachment). The easiest way of retrieving URL for attachment is to use a generated class for your page type. In this case you can get URL of your attachment something like this:

var imageUrl = yourPage.Fields.ContentImage.GetPath();
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.