title: Android Google Drive Resumable Upload fails very often
body: <p>I have problem with uploading mp4 files to google drive. I am using resumable upload. Chunk size is set as multiplicity of minimal size(depending on file size to be uploaded in order to make progress bar working). Upload of small files is working almost always. But when file is about 50 MB upload fails very often. There is exception <code>EOFException</code> at the very beginning of upload or exception "<code>Unexpected end of stream</code>" somewhere in the middle of upload. After many tests it looks that behaviour is random, sometimes working, sometimes not. I am using latest Google Drive API downloaded with eclipse plugin. I am using default authorization with "<code>AccountPicker</code>" activity. I have seen many hints on google search but nothing has solved the problem. For example setting "<code>System.setProperty("http.keepAlive", "false")</code>". This is my upload method:</p>
  
  <pre><code>try{
      final java.io.File fileContent = new java.io.File(path);
      // get MIME type from name:
      String mime = getMimeType(fileContent.getAbsolutePath());
      FileContent mediaContent = new FileContent(mime, fileContent);
  
      // File's meta-data.
      File body = new File();
      body.setTitle(fileContent.getName());
      body.setMimeType(mime);
      // set parent folder:
      body.setParents(Arrays.asList(new ParentReference().setId(parentId)));
  
      Files f = mService.files();
      Insert i = f.insert(body, mediaContent);
      // configure MediaUploader:
      MediaHttpUploader uploader = i.getMediaHttpUploader();
      uploader.setDirectUploadEnabled(false);
      uploader.setProgressListener(new FileUploadProgressListener());
      int chunkSize = getDataChunkSize(fileContent.length());
      uploader.setChunkSize(chunkSize);
      File file = i.execute();
      // upload was interrupted
      if (Thread.interrupted() == true) {
          // file upload was interrupted, currently no action here.
      }
      else if (file != null) {
          // upload finished with success.
      }
      else if (file == null) {
          // upload failed.
      }
  }
  catch (Exception e) {
      // upload failed:
  }
  </code></pre>
  
  <p>I noticed that "<code>EOFException</code>" is generated mainly when google drive is not used for longer time and upload request is done. When for example listing of folders is done and immediately after it upload is done "<code>EOFException</code>" is not generated. I am creating credential object and drive service object only once per activity time life. Maybe some refresh is needed? Could you please help with this? Thanks in advance.</p>