title: Upload large files to AWS bucket in chuncks using Java and OkHttpClient
body: <p>I need to upload large files to an AWS bucket using Java and OkHttpClient3.</p>
  <p>I'm able to upload files in a single chunk and all works well. However, I need to do it in multiple chunks, for example chunks of 500mb. How do I partially send pieces of a file?</p>
  <p>This works well for a single chunck...</p>
  <pre><code>
  import okhttp3.*;
  
  OkHttpClient client = new OkHttpClient().newBuilder()
          .connectTimeout(2400, TimeUnit.SECONDS)
          .writeTimeout(2400, TimeUnit.SECONDS)
          .readTimeout(2400, TimeUnit.SECONDS)
          .build();
  RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
          .addFormDataPart(&quot;Content-Type&quot;, _responseInit.getMultipart_params().getContentType())
          .addFormDataPart(&quot;Policy&quot;, _responseInit.getMultipart_params().getPolicy())
          .addFormDataPart(&quot;X-Amz-Signature&quot;, _responseInit.getMultipart_params().getXamzSignature())
          .addFormDataPart(&quot;acl&quot;, _responseInit.getMultipart_params().getAcl())
          .addFormDataPart(&quot;key&quot;, _responseInit.getMultipart_params().getKey() + &quot;/p1&quot;)
          .addFormDataPart(&quot;success_action_status&quot;, _responseInit.getMultipart_params().getSuccess_action_status())
          .addFormDataPart(&quot;x-amz-algorithm&quot;, _responseInit.getMultipart_params().getXamzAlgorithm())
          .addFormDataPart(&quot;x-amz-credential&quot;, _responseInit.getMultipart_params().getXamzCredential())
          .addFormDataPart(&quot;x-amz-date&quot;, _responseInit.getMultipart_params().getXamzDate())
          .addFormDataPart(&quot;name&quot;, _asset.getName())
          .addFormDataPart(&quot;chunk&quot;, &quot;1&quot;)
          .addFormDataPart(&quot;chunks&quot;, &quot;1&quot;)
          .addFormDataPart(&quot;Filename&quot;, _responseInit.getMultipart_params().getKey() + &quot;/p1&quot;)
          .addFormDataPart(&quot;file&quot;, _asset.getName(),
                  RequestBody.create(MediaType.parse(&quot;application/octet-stream&quot;), _asset))
          .build();
  Request request = new Request.Builder()
          .url(_endPoint)
          .method(&quot;POST&quot;, body)
          .addHeader(&quot;Content-Type&quot;, &quot;multipart/form-data&quot;)
          .build();
  Response response = client.newCall(request).execute();
  </code></pre>
  <p>After each upload of a chunk, I need to register the chunk. So I need to call this code multiple times ...</p>