<?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: File got corrupted while uploading in chunks to dropbox using API calls. in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/File-got-corrupted-while-uploading-in-chunks-to-dropbox-using/m-p/674898#M30432</link>
    <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1656343"&gt;@Impulsum Support&lt;/a&gt; The Dropbox API will accept whatever file data your app provides, exactly as it provides it; it will not perform any additional encoding or decoding. If you supply base64-encoded data, the uploaded data will still have that same base64 encoding. If you wish to upload a non-base64-encoded file, but your data is base64-encoded, you'll need to undo the base64 encoding first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, please refer to my earlier message in this thread for more information on debugging/writing code for this.&lt;/P&gt;</description>
    <pubDate>Thu, 06 Apr 2023 15:43:09 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2023-04-06T15:43:09Z</dc:date>
    <item>
      <title>File got corrupted while uploading in chunks to dropbox using API calls.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/File-got-corrupted-while-uploading-in-chunks-to-dropbox-using/m-p/673851#M30399</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using Apex code, I tried to upload a large (&amp;gt;5MB) file in chunks, But the file is getting corrupted always. Please help me. Below is the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public class relatedFile {&lt;BR /&gt;public String Title;&lt;BR /&gt;public string filepath;&lt;BR /&gt;public Blob VersionData;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;@AuraEnabled(cacheable=false)&lt;BR /&gt;public static string createFile(List&amp;lt;Map&amp;lt;String, Object&amp;gt;&amp;gt; files, Boolean finalChunk, Integer chunksize, string dpaccessToken, string dpteamMemberId,&lt;BR /&gt;string dpfileRootNamespaceId, string dpuploadsession)&lt;BR /&gt;{&lt;BR /&gt;try{&lt;BR /&gt;system.debug('files: '+files);&lt;BR /&gt;Map&amp;lt;String, Object&amp;gt; file = files[0];&lt;BR /&gt;system.debug('file: '+file);&lt;BR /&gt;String fileJson = JSON.serialize(file);&lt;BR /&gt;system.debug('fileJson: '+fileJson);&lt;BR /&gt;relatedFile relatedDocument = (relatedFile) JSON.deserialize(fileJson, relatedFile.class);&lt;BR /&gt;system.debug('relatedDocument.VersionData: '+relatedDocument.VersionData);&lt;BR /&gt;system.debug('relatedDocument.filepath: '+relatedDocument.filepath);&lt;BR /&gt;system.debug('relatedDocument.Title: '+relatedDocument.Title);&lt;BR /&gt;system.debug('finalChunk: '+finalChunk);&lt;BR /&gt;system.debug('chunksize: '+chunksize);&lt;BR /&gt;system.debug('accessToken: '+dpaccessToken);&lt;BR /&gt;system.debug('teamMemberId: '+dpteamMemberId);&lt;BR /&gt;system.debug('fileRootNamespaceId: '+dpfileRootNamespaceId);&lt;BR /&gt;Blob data = relatedDocument.VersionData;&lt;BR /&gt;&lt;BR /&gt;string uploadfileaccesstoken;&lt;BR /&gt;string uploadfileteammemberId;&lt;BR /&gt;string uploadfileroot_namespace_id;&lt;BR /&gt;string uploadsessionid;&lt;BR /&gt;&lt;BR /&gt;System.debug('createFile');&lt;BR /&gt;system.debug('in append data size: '+data.size());&lt;BR /&gt;integer size = 0;&lt;BR /&gt;system.debug('size: '+size);&lt;BR /&gt;&lt;BR /&gt;if(chunksize==0){&lt;BR /&gt;system.debug('in start');&lt;BR /&gt;uploadfileaccesstoken = getAccessToken();&lt;BR /&gt;system.debug('uploadfileaccesstoken: '+uploadfileaccesstoken);&lt;BR /&gt;&lt;BR /&gt;uploadfileteammemberId= getTeamInfo(uploadfileaccesstoken);&lt;BR /&gt;system.debug('teammemberId: '+uploadfileteammemberId);&lt;BR /&gt;&lt;BR /&gt;uploadfileroot_namespace_id = getCurrentAccountInfo(uploadfileaccesstoken,uploadfileteammemberId);&lt;BR /&gt;System.debug('root_namespace_id:' + uploadfileroot_namespace_id);&lt;BR /&gt;&lt;BR /&gt;DropBoxSyncWrapper.EndFileRequest createfilereq = new DropBoxSyncWrapper.EndFileRequest();&lt;BR /&gt;createfilereq.close = false;&lt;BR /&gt;&lt;BR /&gt;Http httpcreatefile = new Http();&lt;BR /&gt;HttpRequest reqcreatefile = new HttpRequest();&lt;BR /&gt;String jsoncreatefile = JSON.serialize(createfilereq);&lt;BR /&gt;System.debug('jsoncreatefile:' + jsoncreatefile);&lt;BR /&gt;reqcreatefile.setHeader('Dropbox-API-Path-Root','{".tag":"root","root":"' + uploadfileroot_namespace_id +'"}');&lt;BR /&gt;reqcreatefile.setHeader('Content-Type', 'application/octet-stream');&lt;BR /&gt;reqcreatefile.setHeader('Dropbox-API-Arg', JSON.serialize(createfilereq));&lt;BR /&gt;reqcreatefile.setHeader('Dropbox-API-Select-User', uploadfileteammemberId);&lt;BR /&gt;reqcreatefile.setHeader('Authorization', 'Bearer '+uploadfileaccesstoken);&lt;BR /&gt;//reqcreatefile.setBodyAsBlob(data);&lt;BR /&gt;reqcreatefile.setMethod('POST');&lt;BR /&gt;//reqcreatefile.setEndpoint('callout:DropBox_API_FileCreate/2/files/upload');&lt;BR /&gt;reqcreatefile.setEndpoint('callout:DropBox_API_FileCreate/2/files/upload_session/start');&lt;BR /&gt;reqcreatefile.setTimeout(120000);&lt;BR /&gt;HttpResponse responsecreatefile = httpcreatefile.send(reqcreatefile);&lt;BR /&gt;system.debug('responsecreatefile: '+responsecreatefile.getBody());&lt;BR /&gt;system.debug('responsecreatefile: '+responsecreatefile.getStatusCode());&lt;BR /&gt;DropBoxSyncWrapper.CheckFileResponse respcreatefile = (DropBoxSyncWrapper.CheckFileResponse) JSON.deserialize(&lt;BR /&gt;responsecreatefile.getBody(), DropBoxSyncWrapper.CheckFileResponse.class);&lt;BR /&gt;System.debug('respcreatefile:' + respcreatefile);&lt;BR /&gt;&lt;BR /&gt;System.debug('respcreatefile.session_id:' + respcreatefile.session_id);&lt;BR /&gt;if(responsecreatefile.getStatusCode()!=200){&lt;BR /&gt;return 'Start Fail';&lt;BR /&gt;}&lt;BR /&gt;uploadsessionid = respcreatefile.session_id;&lt;BR /&gt;}&lt;BR /&gt;else{&lt;BR /&gt;uploadfileaccesstoken = dpaccessToken;&lt;BR /&gt;uploadfileteammemberId = dpteamMemberId;&lt;BR /&gt;uploadfileroot_namespace_id = dpfileRootNamespaceId;&lt;BR /&gt;uploadsessionid = dpuploadsession;&lt;BR /&gt;}&lt;BR /&gt;system.debug('uploadfileaccesstoken: '+uploadfileaccesstoken);&lt;BR /&gt;system.debug('uploadfileteammemberId: '+uploadfileteammemberId);&lt;BR /&gt;system.debug('uploadfileaccesstoken: '+uploadfileroot_namespace_id);&lt;BR /&gt;system.debug('uploadsessionid: '+uploadsessionid);&lt;BR /&gt;if(uploadsessionid!=''){&lt;BR /&gt;Http httpAppendFile = new Http();&lt;BR /&gt;HttpRequest reqAppendFile = new HttpRequest();&lt;BR /&gt;reqAppendFile.setEndpoint('callout:DropBox_API_FileCreate/2/files/upload_session/append_v2');&lt;BR /&gt;String jsstring1 ='{"cursor":{"session_id":"' + uploadsessionid +'","offset":' + chunksize +'},"close":false}';&lt;BR /&gt;System.debug('jsstring1:' + jsstring1);&lt;BR /&gt;reqAppendFile.setHeader('Content-Type', 'application/octet-stream');&lt;BR /&gt;reqAppendFile.setHeader('Dropbox-API-Path-Root','{".tag":"root","root":"' + uploadfileroot_namespace_id +'"}');&lt;BR /&gt;reqAppendFile.setHeader('Dropbox-API-Arg', jsstring1);&lt;BR /&gt;reqAppendFile.setHeader('Dropbox-API-Select-User', uploadfileteammemberId);&lt;BR /&gt;reqAppendFile.setHeader('Authorization', 'Bearer '+uploadfileaccesstoken);&lt;BR /&gt;reqAppendFile.setMethod('POST');&lt;BR /&gt;reqAppendFile.setBodyAsBlob(data);&lt;BR /&gt;HttpResponse responseAppendFile = httpAppendFile.send(reqAppendFile);&lt;BR /&gt;System.debug('responsecreatefile-1:' + responseAppendFile.getStatusCode());&lt;BR /&gt;System.debug('responsecreatefile-1:' + responseAppendFile.getBody());&lt;BR /&gt;if(responseAppendFile.getStatusCode()!=200){&lt;BR /&gt;return 'Append Fail';&lt;BR /&gt;}&lt;BR /&gt;size = data.size()+chunksize;&lt;BR /&gt;system.debug('size: '+size);&lt;BR /&gt;}&lt;BR /&gt;if(finalChunk){&lt;BR /&gt;system.debug('in final chunk');&lt;BR /&gt;&lt;BR /&gt;Http httpUploadFinsh = new Http();&lt;BR /&gt;HttpRequest reqUploadFinish = new HttpRequest();&lt;BR /&gt;reqUploadFinish.setEndpoint('callout:DropBox_API_FileCreate/2/files/upload_session/finish');&lt;BR /&gt;reqUploadFinish.setMethod('POST');&lt;BR /&gt;String jsstring2 ='{"cursor":{"session_id":"' +uploadsessionid +'","offset":' + size +'},"commit":{"path":"' +relatedDocument.filepath +'","mode":"add","autorename":true,"mute":false,"strict_conflict":false}}';&lt;BR /&gt;System.debug('jsstring2:' + jsstring2);&lt;BR /&gt;reqUploadFinish.setHeader('Content-Type', 'application/octet-stream');&lt;BR /&gt;reqUploadFinish.setHeader('Dropbox-API-Path-Root','{".tag":"root","root":"' + uploadfileroot_namespace_id +'"}');&lt;BR /&gt;reqUploadFinish.setHeader('Dropbox-API-Arg', jsstring2);&lt;BR /&gt;reqUploadFinish.setHeader('Dropbox-API-Select-User', uploadfileteammemberId);&lt;BR /&gt;reqUploadFinish.setHeader('Authorization', 'Bearer '+uploadfileaccesstoken);&lt;BR /&gt;//reqUploadFinish.setBodyAsBlob(data);&lt;BR /&gt;HttpResponse responseUploadFinish = httpUploadFinsh.send(reqUploadFinish);&lt;BR /&gt;DropBoxSyncWrapper.createFileResponse createfileresp = (DropBoxSyncWrapper.createFileResponse) JSON.deserialize(&lt;BR /&gt;responseUploadFinish.getBody(), DropBoxSyncWrapper.createFileResponse.class);&lt;BR /&gt;System.debug('responseUploadFinish-2:' + responseUploadFinish.getStatusCode());&lt;BR /&gt;System.debug('responseUploadFinish-2:' + responseUploadFinish.getBody());&lt;BR /&gt;if(responseUploadFinish.getStatusCode()!=200){&lt;BR /&gt;return 'Close Fail';&lt;BR /&gt;}&lt;BR /&gt;system.debug('createfileresp: '+createfileresp.name);&lt;BR /&gt;}&lt;BR /&gt;return size+','+uploadfileaccesstoken+','+uploadfileteammemberId+','+uploadfileroot_namespace_id+','+uploadsessionid;&lt;BR /&gt;}catch(Exception ex){&lt;BR /&gt;Utility.log(true,constant.SystemLogTypes.Callout,'DropBoxSyncHandler','createFile',ex.getMessage(),ex.getStackTraceString(),'','','');&lt;BR /&gt;return 'Fail';&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Javascript/LWC code:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;uploadChunk&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;fileName&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;fileContents&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;fromIndex&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;toIndex&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;accesstoken&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;teamMemberId&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;fileRootNamespaceId&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;uploadsession&lt;/SPAN&gt;&lt;SPAN&gt;){&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;console&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;log&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'In uploadchunk'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;chunk&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;fileContents&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;substring&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;fromIndex&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;toIndex&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;let&lt;/SPAN&gt; &lt;SPAN&gt;isFinalChunk&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;fileContents&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;length&lt;/SPAN&gt;&lt;SPAN&gt; == &lt;/SPAN&gt;&lt;SPAN&gt;toIndex&lt;/SPAN&gt;&lt;SPAN&gt; ? &lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;false&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;filesUploadedtoSalesforce&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;push&lt;/SPAN&gt;&lt;SPAN&gt;({&lt;/SPAN&gt;&lt;SPAN&gt;Title&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;fileName&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;filepath&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;fileorfolderpath&lt;/SPAN&gt;&lt;SPAN&gt;+&lt;/SPAN&gt;&lt;SPAN&gt;'/'&lt;/SPAN&gt;&lt;SPAN&gt;+&lt;/SPAN&gt;&lt;SPAN&gt;fileName&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;VersionData&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;chunk&lt;/SPAN&gt;&lt;SPAN&gt;});&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;createFile&lt;/SPAN&gt;&lt;SPAN&gt;({&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;files&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;filesUploadedtoSalesforce&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;finalChunk&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;isFinalChunk&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;chunksize&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;apexchunkSize&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;dpaccessToken&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;accesstoken&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;dpteamMemberId&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;teamMemberId&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;dpfileRootNamespaceId&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;fileRootNamespaceId&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;dpuploadsession&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;uploadsession&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }).&lt;/SPAN&gt;&lt;SPAN&gt;then&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;result&lt;/SPAN&gt; &lt;SPAN&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt; { &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;console&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;log&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'result: '&lt;/SPAN&gt;&lt;SPAN&gt;+&lt;/SPAN&gt;&lt;SPAN&gt;result&lt;/SPAN&gt;&lt;SPAN&gt;); &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;resarry&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;result&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;split&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;','&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;console&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;log&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;resarry&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;apexchunkSize&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;parseInt&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;resarry&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;]);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;//console.log('this.apexchunkSize: '+this.apexchunkSize);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;fromIndex&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;toIndex&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;toIndex&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Math&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;min&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;fileContents&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;length&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;fromIndex&lt;/SPAN&gt;&lt;SPAN&gt; + &lt;/SPAN&gt;&lt;SPAN&gt;CHUNK_SIZE&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;//this.uploadedsize = toIndex;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;//let isFinalChunk = fileContents.length == toIndex ? true: false;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;fromIndex&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt; &lt;/SPAN&gt;&lt;SPAN&gt;toIndex&lt;/SPAN&gt;&lt;SPAN&gt;) {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;console&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;log&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'In uploadchunk loop'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;uploadChunk&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;fileName&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;fileContents&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;fromIndex&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;toIndex&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;resarry&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;],&lt;/SPAN&gt;&lt;SPAN&gt;resarry&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;],&lt;/SPAN&gt;&lt;SPAN&gt;resarry&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;3&lt;/SPAN&gt;&lt;SPAN&gt;],&lt;/SPAN&gt;&lt;SPAN&gt;resarry&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;&lt;SPAN&gt;]); &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }).&lt;/SPAN&gt;&lt;SPAN&gt;catch&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;error&lt;/SPAN&gt; &lt;SPAN&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; })&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 03 Apr 2023 15:37:01 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/File-got-corrupted-while-uploading-in-chunks-to-dropbox-using/m-p/673851#M30399</guid>
      <dc:creator>Impulsum Support</dc:creator>
      <dc:date>2023-04-03T15:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: File got corrupted while uploading in chunks to dropbox using API calls.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/File-got-corrupted-while-uploading-in-chunks-to-dropbox-using/m-p/673940#M30400</link>
      <description>&lt;P&gt;I see you're attempting to use &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start" target="_blank"&gt;/2/files/upload_session/start&lt;/A&gt;, &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append" target="_blank"&gt;/2/files/upload_session/append_v2&lt;/A&gt;, and &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-finish" target="_blank"&gt;/2/files/upload_session/finish&lt;/A&gt; to upload files. These are &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#formats" target="_blank"&gt;"content-upload" style endpoints&lt;/A&gt;, meaning they require the file data in the request body, with the "application/octet-stream" type. And being upload session endpoints, they allow you to upload large files by doing so in pieces. That is, you can upload the first portion in the call to /2/files/upload_session/start, then further portions in call(s) to /2/files/upload_session/append_v2, and then a final portion in the call to /2/files/upload_session/finish.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you didn't mention how big the files you're trying to upload are beyond being larger than 5 MB, but if they are smaller than 150 MB, for the sake of simplicity you may wish to just use &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload" target="_blank"&gt;/2/files/upload&lt;/A&gt;. That allows you to upload files smaller than 150 MB in one request.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case, I'm not aware of any current issues on the Dropbox API that would result in file uploads from correctly formatted upload sessions requests resulting in corrupted files, and I don't see any other reports like this, so it sounds like that may be some issue(s) in this code/logic that you'll need to correct. We don't offer code debugging services though, so it may be helpful for you to step through your code with a debugger to try to find the issue(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, I see you're setting setBodyAsBlob. That method isn't made by Dropbox so I can't offer support for that in particular, so you may want to refer to its documentation to confirm if that's the right method for this operation. Likewise, check that the data you're supplying is the correct data that you intend to upload, and that your logic for supplying the pieces of the files is right and sends the correct pieces in the correct order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for reference, while it's in a different language, it uses the same upload session endpoints so you may want to check out &lt;A href="https://github.com/dropbox/dropbox-sdk-dotnet/blob/main/dropbox-sdk-dotnet/Examples/SimpleTest/Program.cs#L459" target="_blank"&gt;this example&lt;/A&gt; to see how the logic for using upload sessions works.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 18:38:03 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/File-got-corrupted-while-uploading-in-chunks-to-dropbox-using/m-p/673940#M30400</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-04-03T18:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: File got corrupted while uploading in chunks to dropbox using API calls.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/File-got-corrupted-while-uploading-in-chunks-to-dropbox-using/m-p/674750#M30427</link>
      <description>&lt;P&gt;Here I am uploading Base64 encoded file to dropbox, But the file is getting corrupted. Can you please help me out here.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2023 03:57:21 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/File-got-corrupted-while-uploading-in-chunks-to-dropbox-using/m-p/674750#M30427</guid>
      <dc:creator>Impulsum Support</dc:creator>
      <dc:date>2023-04-06T03:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: File got corrupted while uploading in chunks to dropbox using API calls.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/File-got-corrupted-while-uploading-in-chunks-to-dropbox-using/m-p/674898#M30432</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1656343"&gt;@Impulsum Support&lt;/a&gt; The Dropbox API will accept whatever file data your app provides, exactly as it provides it; it will not perform any additional encoding or decoding. If you supply base64-encoded data, the uploaded data will still have that same base64 encoding. If you wish to upload a non-base64-encoded file, but your data is base64-encoded, you'll need to undo the base64 encoding first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, please refer to my earlier message in this thread for more information on debugging/writing code for this.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2023 15:43:09 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/File-got-corrupted-while-uploading-in-chunks-to-dropbox-using/m-p/674898#M30432</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-04-06T15:43:09Z</dc:date>
    </item>
  </channel>
</rss>

