testa abalez
testa abalez

Reputation: 1062

Google Drive API v3 for iOS : How to get thumbnails?

In the past, with Google Drive API v2, I could easily get thumbnails for pictures or videos with the property thumbnailLink on GTLDriveFile.

But now, with the API v3 which I currently use with Swift, the thumbnailLink of the files I get from Google Drive is nil, so what can I do to get thumbnails of images and videos stored in the user's Google Drive. I need to display theses in my iOS app.

Upvotes: 0

Views: 1743

Answers (2)

abielita
abielita

Reputation: 13494

You'd have to use the Drive REST API method Files: get. The result of that method contains thumbnailLink but according to the documentation it is 'a short-lived link to the file's thumbnail. Typically lasts on the order of hours.

Alternatively, you can cache the thumbnail in your application, reducing the count of drive api requests and thus improve your page performance. You need to fetch the information for the uploaded file. The easiest way of caching is to simply download the thumbnail and save it like fileid_thumb somewhere and upon the next request, you check if such a file exists before actually requesting the thumbnail. Check here the detailed explanation.

You can also upload a thumbnail by setting the contentHints.thumbnail property on the File resource during an insert or update call as follows:

  • Set contentHints.thumbnail.image to the URL-safe Base64-encoded image (see RFC 4648 section 5)
  • Set contentHints.thumbnail.mimeType to the appropriate type for the image format

You can also check the accepted answer in this SO question.

Hope this helps!

Upvotes: 0

ethanchli
ethanchli

Reputation: 296

Make sure to specify thumbnailLink in fields, such as

let query = GTLQueryDrive.queryForFilesList()
query.fields = "files(id, name, thumbnailLink)"

then you can access the property thumbnailLink for images and videos

Upvotes: 3

Related Questions