I use the following code to set thumb nail for file to upload on Google Drive :
// Set thumb nail path
String thumbnail_path =
You need to provide the Base64 encoded image content instead of the path.
final Thumbnail thumbnail = new Thumbnail();
thumbnail.setMimeType("image/jpeg");
thumbnail.setImage(base64encodedContent);
You decode the data from the getData
method that are not encoded.
You should also use Base64.encodeBase64URLSafeString
instead of Base64.encodeBase64String
. You can use File.Thumbnail.encodeImage method as a convenience. That will do the encoding for you.
Replace this:
byte[] data = Base64.decodeBase64(getData(thumbnail_path));
thumbnail.setImage(Base64.encodeBase64String(data));
with this:
byte[] data = getData(thumbnail_path);
thumbnail.encodeImage(data);