In a previous article, we have seen how to generate a document thumbnail from its metadata (siteId, webId, uniqueId, docId…) retrieved from the search engine.
With these metadata, you just have to build and call an URL such as the following :
https://tenant.sharepoint.com/_layouts/15/getpreview.ashx?guidFile=<GUID>&guidSite=<GUID>&guidWeb=<GUID>&docid=<Int>&metadatatoken=<String>
Although easy to implement, this solution is not convenient every time, especially when you don’t use the search engine to retrieve data.
For example, when you use the Video REST API or the SharePoint REST API to manipulate list items, you don’t retrieve some of the required properties to generate the preview as described in our previous article.
One solution should be to query the search engine for the associated file to retrieve required metadata, then build and call the URL to generate the preview. This solution works very well but it’s pretty inefficient because you have to make 2 requests for each thumbnail.
A better solution based on the same HTTP Handler
Last week, I was working on different things around Office 365 and I discovered a better solution based on the same HTTP Handler.
It’s possible, rather than passing many parameters (siteId, webId, docId…), to pass only one parameter called ‘path’.
This parameter expects a value equal to the URL of the document/file for which you want to generate a thumbnail. To generate a preview, the URL should look like this :
https://tenant.sharepoint.com/portals/hub/_layouts/15/getpreview.ashx?path=https%3A%2F%2Ftenant.sharepoint.com%2Fportals%2Fcommunity%2FpVid%2FBiking%2520to%2520Work.mp4
In the sample above which generates a thumbnail for a video stored in an Office 365 video channel), you just have to encode the path of the file, and add it to the querystring for the ‘path‘ parameter.
I have tested with many file types (Word, Excel, PowerPoint, MP4…), stored in different containers (document libraries, video channels…) and it works for each of them.
For information, this solution is used by Delve to generate thumbnails for video files stored in Office 365 Video 😉
You explained very well manner and easy to understand ..Keep it up
LikeLiked by 1 person
good information..Looking for more topics
LikeLike
Interesting topic. I want to learn some more on this topic.
LikeLike
Pingback: How to know what file types are supported to generate previews on Office 365 ? | Beecome Digital
This is great!
LikeLiked by 1 person
Pingback: CSOM GetImagePreviewUrl Parameters | Question and Answer
is this still working? I’m getting 400 bad request, when I tried for a document which is in a Document Library.
LikeLike
I’m getting 404 when entering the below url on browser (replaced with actual) :
[video src="https://.sharepoint.com/portals/hub/_layouts/15/getpreview.ashx?path=https%3A%2F%2F.sharepoint.com%2Fsites%2Fdev%2FLeap%2520Videos%2FSimon_Joh__Good_leaders.mp4" /]
LikeLike
This is not working. Can you post more about this. Thank you.
LikeLike
This is great!
I have a PowerPoint template library. Want to display the preview in Powerpoint 2016 taskpane. So that users can search and insert slides. is it possible?
Though I am able to get the preview in the browser as you mentioned in the article, I am not able to bind the image to a image control.
Thanks,
LikeLiked by 1 person
Is there any documentation about all the ¶meters that can be used with getpreview.ashx ? I can’t find anything…
LikeLike