title: Set thumbnail image for uploading on Google Drive
body: <p>I use the following code to <strong>set thumb nail for file to upload</strong> on Google Drive :</p>
  
  <pre><code>// Set thumb nail path                  
  String thumbnail_path = mediaContent.getFile().getAbsolutePath();   
  // thumbnail_path : "/sdcard/Picture/ds01.jpg" 
  
  // File's meta data.                    
  File body = new File();                 
  body.setTitle(fileContent.getName());                   
  body.setMimeType("image/jpeg");
  
  // Thumb nail                   
  final Thumbnail thumbnail = new Thumbnail();                    
  thumbnail.setMimeType("image/jpeg");            
  
  // UPDATE HERE : define byte array
  byte[] data = Base64.decodeBase64(getData(thumbnail_path));  
  thumbnail.encodeImage(Base64.encodeBase64String(data));
  
  // set thumb nail for file
  body.setThumbnail(thumbnail);
  </code></pre>
  
  <p>The code run successful, but I think something wrong, i don't know where.
  Because I used following code to get information related to file, and the <strong>file.getThumbnail() is null</strong>. (<em>getTitle() and getMimeType() is successful</em>).</p>
  
  <pre><code>private static void printFile(Drive service, String fileId) {
          try {
              File file = service.files().get(fileId).execute();
  
              System.out.println("Title: " + file.getTitle());
              System.out.println("MIME type: " + file.getMimeType());
              System.out.println("getThumbnail: " + file.getThumbnail());
          } catch (IOException e) {
              System.out.println("An error occured: " + e);
          }
      }
  </code></pre>
  
  <p>The following code is for uploading, it successful :</p>
  
  <pre><code>String folderId = ManageFile.getIdLink();
  Log.d(TAG, "folderId " + folderId);
  body.setParents(Arrays.asList(new ParentReference().setId(folderId)));
  
  File file = service.files().insert(body, mediaContent).execute();
  </code></pre>
  
  <p><strong>UPDATE :</strong>
  - I add those code for describe how to get byte array.</p>
  
  <pre><code>protected byte[] getData(String thumbnail_path) {
          byte[] imageData = null;
          final int THUMBNAIL_SIZE = 96;
  
          FileInputStream fis;
          try {
              fis = new FileInputStream(thumbnail_path);
  
              Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
              imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);
  
              ByteArrayOutputStream baos = new ByteArrayOutputStream();  
              imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
  
              // byte data array
              imageData = baos.toByteArray();
  
              return imageData;
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
          return null;
      }
  </code></pre>
  
  <p>p/s : 
  - <a href="https://developers.google.com/drive/v2/reference/files/get#try-it" rel="nofollow">Get file</a>
  - <a href="https://developers.google.com/drive/v2/reference/files#resource" rel="nofollow">File resource</a></p>
  
  <p>Please tell me how to <strong>get Thumb nail image successful</strong>.
  Thanks!</p>