bjernie
bjernie

Reputation: 178

Google Drive API not displaying thumbnail

I have an app that uses the Google Drive API, and I need to display the thumbnails. But when I pass the link to an <img> tag it responds with a 404, but if I open the link manually in another tab in my browser it display just fine

Upvotes: 1

Views: 1394

Answers (1)

Tanaike
Tanaike

Reputation: 201713

  • You want to put the thumbnail of the file retrieved from Google Drive to your HTML.
    • The thumbnail link is retrieved by Drive API.
  • When you put it and open the HTML, 404 is returned. But when you directly access to the URL of the thumbnail link, you can see the image on your browser.

I believe your goal and your issue like above. For this, how about this answer?

Issue and workaround:

From your situation, I think that when you directly access to the thumbnail link, you might have logged in Google Account. By this, the image can be seen. And also, I thought that you might have used the following thumbnail link. This is the thumbnail link retrieved by Drive API.

https://docs.google.com/feeds/vt?gd=true&id={fileId}&v=1&s=###&sz=s220

Unfortunately, it seems that this link cannot be directly used at the HTML of outside. So in order to use the thumbnail at the HTML of outside, how about changing the endpoint?

Modified endpoint:

https://drive.google.com/thumbnail?sz=w640&id={fileId}
  • Please replace {fileId} of your file ID.
  • w640 means 640 pixels in the width. If you want to change the height, please useh instead of w.
  • Please share publicly the file you want to retrieve the thumbnail. It's On - Anyone with the link. By this, above link can be used. Please be careful this.

Note:

  • When the following HTML is used with the above link, the thumbnail can be seen.

    <img src="https://drive.google.com/thumbnail?sz=w640&id={fileId}">
    

Upvotes: 3

Related Questions