<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Chunked upload with HTTP requests in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89079#M2738</link>
    <description>&lt;P&gt;It looks like you're sending&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/MIME#Form-Data" target="_blank" rel="nofollow noreferrer"&gt;multipart form data&lt;/A&gt;, which explains the extra data you're sending. You&amp;nbsp;should instead be sending the raw&amp;nbsp;bytes of the file as the body of the HTTP request.&lt;/P&gt;
&lt;P&gt;From a quick search, I think&amp;nbsp;ByteArrayEntity is what you want (instead of MultipartEntity).&lt;/P&gt;</description>
    <pubDate>Wed, 02 Sep 2015 22:03:24 GMT</pubDate>
    <dc:creator>Steve M.</dc:creator>
    <dc:date>2015-09-02T22:03:24Z</dc:date>
    <item>
      <title>Chunked upload with HTTP requests</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89076#M2735</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to implement chunked upload utilizing HTTP requests and find myself in trouble with chunked upload.&lt;/P&gt;
&lt;P&gt;The upload itself seems to work fine, i am able to go through the flow and receive 200 response and uploaded files metadata after calling commit_chunked_upload, however&amp;nbsp;the uploaded file(s) seem(s) to be corrupted.&lt;/P&gt;
&lt;P&gt;Tested chunked upload with:&lt;/P&gt;
&lt;P&gt;.mp4 video - unable to preview, when downloaded unable to view properly&lt;/P&gt;
&lt;P&gt;.psd file - unable to preview, when downloaded unable to view properly&lt;/P&gt;
&lt;P&gt;.pdf file - unable to preview, when downloaded, surprisingly opens up just fine.&lt;/P&gt;
&lt;P&gt;I am&amp;nbsp;uploading in 4MB (4*1024*1024)&amp;nbsp;chunks and noticed when debugging that returned offset is larger than the chunk that im sending, for instance&amp;nbsp;&lt;/P&gt;
&lt;P&gt;chunk &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;returned offset&lt;/P&gt;
&lt;P&gt;4194304 &amp;nbsp; &amp;nbsp; &amp;nbsp; 4194507&lt;/P&gt;
&lt;P&gt;4194304 &amp;nbsp; &amp;nbsp; &amp;nbsp; 8389010&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;chunks are sent as PUT&amp;nbsp;requests body&lt;/P&gt;
&lt;P&gt;What could possible be causing the problem that files become corrupted (im guessing)?&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:40:18 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89076#M2735</guid>
      <dc:creator>Arthur C.9</dc:creator>
      <dc:date>2019-05-29T09:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Chunked upload with HTTP requests</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89077#M2736</link>
      <description>&lt;P&gt;My guess would be&amp;nbsp;an encoding bug on your side. (Perhaps you're treating the data as text instead of binary?)&lt;/P&gt;
&lt;P&gt;Can you share your code?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2015 21:47:33 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89077#M2736</guid>
      <dc:creator>Steve M.</dc:creator>
      <dc:date>2015-09-02T21:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: Chunked upload with HTTP requests</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89078#M2737</link>
      <description>&lt;PRE&gt;Written in scala, so far for testing purposes no other handling is done. Due to the need to have 100% e2e test coverage it was decided against using java SDK (mainly due to having trouble supplying local trusted-certs.jks, seemed easier overall to just do everything with plain HTTP requests)&lt;BR /&gt;&lt;BR /&gt;for debugging purposes there are certain variables made just to see more data, but not used, please disregard that&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;def chunkedUpload(): Any = {&lt;BR /&gt;&lt;BR /&gt;  val fileToUpload = new File(getClass.getClassLoader.getResource("files/app.psd").toURI)&lt;BR /&gt;  val defaultChunkSize: Int = 4 * 1024 * 1024&lt;BR /&gt;  val fileInByteArray = Files.readAllBytes(fileToUpload.toPath)&lt;BR /&gt;  val httpClient = HttpClients.createDefault()&lt;BR /&gt;  val length = fileInByteArray.length&lt;BR /&gt;  val chunkingCounter = fileInByteArray.length / defaultChunkSize + 1&lt;BR /&gt;&lt;BR /&gt;  def getChunk(byteArray: Array[Byte], counter: Int, chunkSize: Int = defaultChunkSize): HttpEntity = {&lt;BR /&gt;&lt;BR /&gt;    val byteArrayLength = byteArray.length&lt;BR /&gt;&lt;BR /&gt;    if (counter == 0) {&lt;BR /&gt;&lt;BR /&gt;      val multipartEntityBuilder = MultipartEntityBuilder.create()&lt;BR /&gt;&lt;BR /&gt;      if (byteArrayLength &amp;lt;= chunkSize) {&lt;BR /&gt;        val chunk = byteArray&lt;BR /&gt;        val chunklength = chunk.length&lt;BR /&gt;        multipartEntityBuilder.addBinaryBody("chunk", chunk)&lt;BR /&gt;        val requestBody = multipartEntityBuilder.build()&lt;BR /&gt;        requestBody&lt;BR /&gt;      }&lt;BR /&gt;      else {&lt;BR /&gt;        val chunk = byteArray.slice(0, chunkSize)&lt;BR /&gt;        val chunklength = chunk.length&lt;BR /&gt;        multipartEntityBuilder.addBinaryBody("chunk", chunk)&lt;BR /&gt;        val requestBody = multipartEntityBuilder.build()&lt;BR /&gt;        requestBody&lt;BR /&gt;      }&lt;BR /&gt;    }&lt;BR /&gt;    else {&lt;BR /&gt;      val leftoverArray = byteArray.drop(chunkSize)&lt;BR /&gt;      val leftoverLength = leftoverArray.length&lt;BR /&gt;      getChunk(leftoverArray, counter - 1, chunkSize)&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  def uploadChunk(requestBody: HttpEntity, uploadUrl: String): DBObject = {&lt;BR /&gt;    val uploadRequest = new HttpPut(uploadUrl)&lt;BR /&gt;    uploadRequest.setHeader("Authorization", s"Bearer $token")&lt;BR /&gt;    uploadRequest.setEntity(requestBody)&lt;BR /&gt;    val response = httpClient.execute(uploadRequest)&lt;BR /&gt;    val parsedResponse = JSON.parse(EntityUtils.toString(response.getEntity)).asInstanceOf[DBObject]&lt;BR /&gt;    parsedResponse&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  def commitChunkedUpload(uploadUrl: String, uploadId: String): Any = {&lt;BR /&gt;    val commitUploadRequest = new HttpPost(uploadUrl)&lt;BR /&gt;    commitUploadRequest.setHeader("Authorization", s"Bearer $token")&lt;BR /&gt;    val postParameters = new util.ArrayList[NameValuePair]()&lt;BR /&gt;    postParameters.add(new BasicNameValuePair("upload_id", uploadId))&lt;BR /&gt;    postParameters.add(new BasicNameValuePair("overwrite", "true"))&lt;BR /&gt;    commitUploadRequest.setEntity(new UrlEncodedFormEntity(postParameters))&lt;BR /&gt;    val commitResponse = httpClient.execute(commitUploadRequest)&lt;BR /&gt;    val parsedResponse = JSON.parse(EntityUtils.toString(commitResponse.getEntity)).asInstanceOf[DBObject]&lt;BR /&gt;    parsedResponse&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  def executeChunkedUpload(counter: Int, uploadId: String = ", offset: Long = 0): Any = {&lt;BR /&gt;    if (counter == chunkingCounter) commitChunkedUpload(&lt;BR /&gt;      s"https://content.dropboxapi.com/1/commit_chunked_upload/auto/Stuff/add%20pdf.psd", uploadId) //try setting parameters as post params instead of URL&lt;BR /&gt;    else {&lt;BR /&gt;      val requestBody = getChunk(fileInByteArray, counter)&lt;BR /&gt;      val uploadUrl = s"https://content.dropboxapi.com/1/chunked_upload?upload_id=$uploadId&amp;amp;offset=$offset"&lt;BR /&gt;      val intermediaryResponse = uploadChunk(requestBody, uploadUrl)&lt;BR /&gt;      val newOffset = intermediaryResponse.get("offset").asInstanceOf[Int]&lt;BR /&gt;      val rewriteId = intermediaryResponse.get("upload_id").asInstanceOf[String]&lt;BR /&gt;      executeChunkedUpload(counter + 1, rewriteId, newOffset)&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  executeChunkedUpload(0)&lt;BR /&gt;&lt;BR /&gt;}&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Sep 2015 21:55:06 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89078#M2737</guid>
      <dc:creator>Arthur C.9</dc:creator>
      <dc:date>2015-09-02T21:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Chunked upload with HTTP requests</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89079#M2738</link>
      <description>&lt;P&gt;It looks like you're sending&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/MIME#Form-Data" target="_blank" rel="nofollow noreferrer"&gt;multipart form data&lt;/A&gt;, which explains the extra data you're sending. You&amp;nbsp;should instead be sending the raw&amp;nbsp;bytes of the file as the body of the HTTP request.&lt;/P&gt;
&lt;P&gt;From a quick search, I think&amp;nbsp;ByteArrayEntity is what you want (instead of MultipartEntity).&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2015 22:03:24 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89079#M2738</guid>
      <dc:creator>Steve M.</dc:creator>
      <dc:date>2015-09-02T22:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: Chunked upload with HTTP requests</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89080#M2739</link>
      <description>&lt;P&gt;Just switched to&amp;nbsp;ByteArrayEntity as you suggested and everything works as intented!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2015 22:11:49 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Chunked-upload-with-HTTP-requests/m-p/89080#M2739</guid>
      <dc:creator>Arthur C.9</dc:creator>
      <dc:date>2015-09-02T22:11:49Z</dc:date>
    </item>
  </channel>
</rss>

