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"
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.