Set thumbnail image for uploading on Google Drive

前端 未结 2 856
梦如初夏
梦如初夏 2021-01-27 08:52

I use the following code to set thumb nail for file to upload on Google Drive :

// Set thumb nail path                  
String thumbnail_path =         


        
相关标签:
2条回答
  • 2021-01-27 09:43

    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);
    
    0 讨论(0)
  • 2021-01-27 09:48

    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);
    
    0 讨论(0)
提交回复
热议问题