1

I am using Microsoft Graph to preview an item stored in SharePoint.

I tried the driveItem: preview API and I am getting a URL return like this:

https://{domain}.sharepoint.com/_layouts/15/embed.aspx?uniqueId={guid}&access_token=eyJ0eXAiOiJKV...

But when I am rendering it into a div, then it is showing this error:

"Hmm... looks like this file does not have a preview we can show"

enter image description here

Below is the code from the .aspx page:

function OpenDocument(fileURL, filename) {
    var path = filename;
    var ext = path.substring(path.lastIndexOf(".") + 1, path.length).toLowerCase();

    var object = "<object data=\"{FileName}\" class=\"{CP}\">";  //Add class if PDF file is uploaded 
    object += "If you are unable to view file, you can download from <a href=\"{FileName}\" target = \"_blank\">here</a>";
    object += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
    object += "</object>";
    object = object.replace(/{FileName}/g, fileURL);

    var iframe = '';

    if (ext == 'pdf') { //Add class if PDF file is uploaded 
        object = object.replace(/{CP}/g, "clsPdf");  //G16052017
        $("#dialogContent").html(object);
    }
    else {
        iframe += "<embed src='" + fileURL + "' />";
        $("#dialogContent").html(iframe);
    }

    ShowDocumentPopup();
    return false;
} 

I have also passed the preview URI to an embedded tag and with an iframe but neither worked.

Is this an HTML rendering issue or does SharePoint have some limitations in showing previews for images?

NOTE: I have added a fake Preview URL for your reference, just to show you the format of the URL sent by Preview API.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63

1 Answers1

0

The documentation isn't very clear but it was my understanding that the "preview" endpoint was more indented for embedding document previews. What you're describing sounds more like a file thumbnail and there is a specific endpoint for that: List thumbnails for a DriveItem. This returns a set of file thumbnails for a given file:

{
  "value": [
    {
      "id": "0",
      "small": { "height": 64, "width": 96, "url": "https://sn3302files..."},
      "medium": { "height": 117, "width": 176, "url": "https://sn3302files..."},
      "large": { "height": 533, "width": 800, "url": "https://sn3302files..."}
    }
  ]
}

You can also request the thumbnail content via the API:

GET /sites/{site-id}/drive/items/{item-id}/thumbnails/{thumb-id}/{size}/content
Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63