I have the below code which allows me to get all type of document URL for SharePoint which can be opened from link but there are images when trying to open it load the same page

here is a format for URL

<a target='_blank'  href='"+data.d.results[i].ServerRedirectedEmbedUrl+"'>"+data.d.results[i].FileLeafRef+"</a>

function getList() {        
      var fullUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Reports')/items?$top=1000&$select=Created,Author/FirstName,Author/LastName,FileLeafRef,ServerRedirectedEmbedUrl&$expand=Author/Id&$filter=FSObjType eq 0";
        url: fullUrl,
        type: "GET",
        headers: {
          "accept": "application/json;odata=verbose",
          "content-type": "application/json;odata=verbose",
        success: onQuerySucceeded,
        error: onQueryFailed

    function onQuerySucceeded(data) {
      var listItemInfo = " ";
      for (var i = 0; i < data.d.results.length; i++) {  
            if (data.d.results[i].FileSystemObjectType != 1) { 
        listItemInfo += "<div class=panel-heading><h4><a target='_blank'  href='"+data.d.results[i].ServerRedirectedEmbedUrl+"'>"+data.d.results[i].FileLeafRef+"</a></h4><p>"+String.format("{0:d}",new Date(data.d.results[i].Created))+",&nbsp;"+data.d.results[i].Author.FirstName+"&nbsp;"+data.d.results[i].Author.LastName+"</p></div>";
    function onQueryFailed() {

1 Answer 1


According to my research and testing, the following code can achieve the function of getting the Image URL from SharePoint document library, you can refer to :

function GetListItemByTitle() {
   url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Test')/Items?$select=FileRef/FileRef", 
   type: "GET", 
   headers: {"accept": "application/json;odata=verbose"}, 
   success: function (data) { 
      if (data.d.results) { 
         // TODO: handle the data  
   error: function (xhr) { 
      alert(xhr.status + ': ' + xhr.statusText); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.