Added preview for the thumbnail sample
This commit is contained in:
parent
93bdf2ee95
commit
b87f54e86c
|
@ -3,6 +3,11 @@
|
|||
## Summary
|
||||
A web part showcasing how to call the [Microsoft Graph Thumbnails API](https://docs.microsoft.com/en-us/graph/api/driveitem-list-thumbnails) to generate a preview image for files and pages in SharePoint. The sample illustrates how to craft the preview URL both from a search result as well as from a SharePoint item object.
|
||||
|
||||
_Note that a preview for all file formats (eg. Excel) might not currently be available._
|
||||
|
||||
![web part sample](./preview.gif)
|
||||
|
||||
|
||||
The sample calls the Microsoft Graph API directly directly via the _api/2.0 endpoint in SharePoint Online, but can easily be changed to call the Graph API endpoint directly for scenarios outside of SharePoint as long as an access token is retrieved.
|
||||
|
||||
The goal of the sample is to illustrate a single call calling pattern for the thumbnail with the following calling pattern:
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.8 MiB |
|
@ -47,13 +47,13 @@ export default class ThumbnailWebPart extends BaseClientSideWebPart<void> {
|
|||
let fileName = fileInfo["FileLeafRef"];
|
||||
|
||||
let thumbnailUrl = `/_api/v2.0/sites/${this.context.pageContext.site.id}/lists/${listId}/items/${itemUniqueId}/driveItem/thumbnails/0/${maxHeight}/content${noRedirect}`;
|
||||
_documentResults += (`<li>${fileName}<br/><img height="150" border="1" src="${thumbnailUrl}"></li>`);
|
||||
_documentResults += (`<li>${fileName}<br/><img height="150" border="1" src="${thumbnailUrl}" onerror="this.src=''"></li>`);
|
||||
|
||||
});
|
||||
|
||||
searchResults.PrimarySearchResults.forEach(item => {
|
||||
let thumbnailUrl = `/_api/v2.0/sites/${item["NormSiteID"]}/lists/${item["NormListID"]}/items/${item["NormUniqueID"]}/driveItem/thumbnails/0/${maxHeight}/content${noRedirect}`;
|
||||
_searchResults += (`<li>${item["FileName"]}<br/><img height="150" border="1" src="${thumbnailUrl}"></li>`);
|
||||
_searchResults += (`<li>${item["FileName"]}<br/><img height="150" border="1" src="${thumbnailUrl}" onerror="this.src=''"></li>`);
|
||||
});
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue