I've been working on adding thumbnails to the files that I upload to Google Drive using Javascript. I'm following the instructions outlined at https://developers.google.com/drive/v3/web/file#uploading_thumbnails
For my web-safe base64 image, I converted a simple red-square image to base64 using an online tool, which resulted in:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP4z8DwHwAFAAH/VscvDQAAAABJRU5ErkJggg==
After extracting the string following data:image/png;
, replacing /
with _
and removing any trailing =
's, I ended up with:
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP4z8DwHwAFAAH_VscvDQAAAABJRU5ErkJggg
I then included the following snippet in the header of my request:
contentHints: {
thumbnail: {
image: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP4z8DwHwAFAAH_VscvDQAAAABJRU5ErkJggg",
mimeType: "image/png"
}
}
Despite these efforts, I am unable to see any thumbnails for my files, both in list and grid view within Google Drive.
Any ideas as to why this might be happening?
Below is my complete code for saving files:
function saveFile(content) {
var boundary = '-------314159265358979323846';
var header = JSON.stringify({
title: "My file",
mimeType: "application/myFile",
parents: ['root'],
contentHints: {
thumbnail: {
image: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP4z8DwHwAFAAH_VscvDQAAAABJRU5ErkJggg",
mimeType: "image/png"
}
}
});
var method = 'POST';
var path = "/upload/drive/v2/files";
var body = [
"\r\n--" + boundary + "\r\nContent-Type: application/json\r\n\r\n" + header,
"\r\n--" + boundary + "\r\nContent-Type: " + this.mimeType + "\r\n\r\n" + (content.getContentAsJSON()),
"\r\n--" + boundary + "--"].join('');
var request = gapi.client.request({
path: path,
method: method,
params: {
uploadType: 'multipart'
},
headers: {
'Content-Type': 'multipart/related; boundary="' + boundary + '"'
},
body: body
});
request.execute(file);
};