title: Resumable YouTube uploads with YouTube Data API v3 in Android
body: <p>I'm uploading videos to my YouTube account from my Android application using <a href="https://developers.google.com/youtube/v3/" rel="nofollow">YouTube Data API v3</a>. Uploading process works perfectly. What I need is, if my upload got interrupted (eg. because of Internet connection) I need to start upload next time where it left.</p>
  
  <pre><code>private void uploadVideo(UploadInfo videoInfo) {
  
      Insert videoInsert = prepareUpload( new File(videoInfo.getFilePath()) );
  
      new VideoUploadAsyncTask(videoInfo, getActivity(), videoUploadAsyncTaskInterface).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, videoInsert);
  }
  
  public Insert prepareUpload( File videoFile ) {
  
      try {
          Video videoObjectDefiningMetadata = new Video();
  
          VideoStatus status = new VideoStatus();
          status.setPrivacyStatus("public");
          videoObjectDefiningMetadata.setStatus(status);
  
          VideoSnippet snippet = new VideoSnippet();
  
          snippet.setTitle(videoFile.getName());
          snippet.setDescription("Uploaded via AnujAroshA Android app");
  
          List&lt;String&gt; tags = new ArrayList&lt;String&gt;();
          tags.add("AnujAroshA");
          snippet.setTags(tags);
  
          videoObjectDefiningMetadata.setSnippet(snippet);
  
          InputStreamContent mediaContent = new InputStreamContent(VIDEO_FILE_FORMAT, new BufferedInputStream(new FileInputStream(videoFile)));
          mediaContent.setLength(videoFile.length());
  
          YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,status", videoObjectDefiningMetadata, mediaContent);
  
          MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();
  
          uploader.setDirectUploadEnabled(false);
  
          uploader.setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE);
  
          return videoInsert;
      } catch (FileNotFoundException e) {
          return null;
      } catch (IOException e) {
          return null;
      }    
  }
  </code></pre>
  
  <p>How can I do that?</p>
  
  <hr>
  
  <p>Update with VideoUploadAsyncTask class doInBackground method</p>
  
  <pre><code>@Override
  protected String doInBackground( Insert... inserts ) {
  
      try{
  
          Insert videoInsert = inserts[0];
  
          MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();
  
          MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() {
  
              @Override
              public void progressChanged(MediaHttpUploader uploader) throws IOException {
  
                  switch (uploader.getUploadState()) {
                  case INITIATION_STARTED:
                      Log.d(TAG, "# INITIATION_STARTED ");
                      break;
  
                  case INITIATION_COMPLETE:
                      Log.d(TAG, "# INITIATION_COMPLETE ");
                      break;
  
                  case MEDIA_IN_PROGRESS:
                      int progress = (int) Math.round(uploader.getProgress() * 100);
                      Log.d(TAG, "# MEDIA_IN_PROGRESS : progress = " + progress + "%");
  
                      publishProgress(progress);
                      break;
  
                  case MEDIA_COMPLETE:
                      Log.d(TAG, "# MEDIA_COMPLETE ");
                      publishProgress(100);
                      break;
  
                  case NOT_STARTED:
                      Log.d(TAG, "# NOT_STARTED ");
                      break;
  
                  default:
                      break;
                  }
              }
          };
  
          uploader.setProgressListener(progressListener);
  
          Video returnedVideo = videoInsert.execute();
  
          return returnedVideo.getId();
  
      }catch(GooglePlayServicesAvailabilityIOException gpsaioe){
  
      }catch(UserRecoverableAuthIOException uraioe){
  
      }catch(GoogleAuthIOException gaioe){
  
      }catch(IOException ioe){
  
      }       
      return null;
  }
  </code></pre>