How to get image in a sharepoint page using rest api jquery?

Gulnar 146 Reputation points
2020-10-13T11:58:26.727+00:00

I have an announcement list that contains title, body and image column for each item. And I have a page that should return the last item (title,body and image) from announcement list. Now I have the rest API jquery that is ready to get the body and the title. But I don't know how to return the image of the item itself in the code.
Can anyone help me?
31975-anno.txt

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,566 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Gulnar 146 Reputation points
    2020-10-14T04:11:12.217+00:00

    No answer on my question

    0 comments No comments

  2. MichaelHan-MSFT 18,031 Reputation points
    2020-10-14T04:28:30.043+00:00

    Hi @Gulnar ,

    What's the type of your image column? Is it Hyperlink or Picture?

    If so, you could try to use this:

    $("#image").html("<img src='" + data.d.results[0].Image.Url +"'>");  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. MichaelHan-MSFT 18,031 Reputation points
    2020-10-14T06:26:03.413+00:00

    Hi @Gulnar ,

    Per my test, when I use Image column in the list. I get this value for the image column in the rest api :

    32241-image.png

    We need to get the serverRelativeUrl from the string. You could use the below code to get this;

     var image=data.d.results[0].Image.match('"serverRelativeUrl":(.*),"id"');  
     $("#image").html("<img src="+ image[1] + ">");     
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.