You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

DrunkenMoose's avatar
DrunkenMoose
Explorer | Level 3
4 years ago

Dropbox upload session append - incorrect offset

Hey,

 

I'm working on a dropbox upload function in java (coldfusion). The simpel upload works perfectly, but I'm having troubles with the session upload. Here is what I try to do:

 

>I have an image (20 MB)

>I start the session and add the first chunk (chunks of 4 MB = 4194304 KB)

>The first append I call after the start session returns a 409 error

 

The weird part is the following: on the start I already sent the first chunk of 4MB. So I guess that the first append should have an offset of 4MB. The funny thing is that the error states that I should have a offset of 8024827KB.

 

I have no idea where dropbox gets this number from. And when I follow this for all the chunks then I get a corrupted file of 40MB. 

Is this logic wrong? If you want to see some code I could do that, but I don't think that's it.

 

Also the weird part is, is when I do chunks of 150 MB (so it skips the append) then it works perfectly...

It seems that the append doesn't correctly handle the offset.

 

Thanks in advance!

 

P.S. here is the append code:

var used_offset = (loop_counter - 1) * max_chunk_size;
var stuResponse = {};
var httpService = new http();
httpService.setMethod("POST"); 
httpService.setCharset("utf-8");
httpService.setUrl("https://content.dropboxapi.com/2/files/upload_session/append_v2");
httpService.addParam(type="header", name="Authorization", value="Bearer #gebruikte_token#");
httpService.addParam(type="header", name="Dropbox-API-Arg", value="#serializeJSON({
     "cursor" : {
            "session_id" : upload_doc_session,
            "offset" : used_offset
     },
     "close" : close_con
})#");
httpService.addParam(type="header", name="Content-type", value="application/octet-stream");
httpService.addParam(type="body", value="#chunk#");
var result = httpService.send().getPrefix();

if(structKeyExists(result.ResponseHeader, 'Status_Code') && result.ResponseHeader['Status_Code'] eq '200'){
}
else{
   return ["ERROR", "2 GET: URL geeft een fout. Code: #result.Statuscode# - #result['status_text']# - #result['errordetail']#", result, used_offset, close_con];
}
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    If the first /2/files/upload_session/append_v2 call is failing with 'incorrect_offset', and indicating a 'correct_offset' of 8024827 for that upload session, then that indicates that the API received that much data for that upload session in the /2/files/upload_session/start call. That is, the 'correct_offset' value indicates how much data the API has received so far for that upload session. If this number is higher than expected, it's likely that your code is accidentally sending more data per call than you intended.

     

    I recommend debugging your code for calling /2/files/upload_session/start to make sure you're only sending as much data as you intended, i.e., "4194304 KB" in this case, from your description. (By the way, did you mean bytes instead of KB? 4 MB = 4194304 bytes, not KB.)

     

    Also, it makes sense that it would work if you use a chunk size of 150 MB for a 20 MB file, since you would be uploading the entire file in the /2/files/upload_session/start call, and so wouldn't need to use /2/files/upload_session/append_v2, so the offset value doesn't need to be checked.

    • DrunkenMoose's avatar
      DrunkenMoose
      Explorer | Level 3

      Hey,

       

      First of all, thanks for the quick response! Well that's what I thought! The error indeed states that the first call supposetly sends 8mb data. I made another test example, which is more simple, and I still get the same error. And when I dump the first chunk, it says it's 4mb.. here look at this (I removed unnecessary code):

       

       

      var max_chunk_size = 4 * 1024 * 1024;
      var stuResponse = {}; var httpService = new http(); httpService.setUrl("https://content.dropboxapi.com/2/files/upload_session/start"); httpService.addParam(type="header", name="Dropbox-API-Arg", value="#serializeJSON({ "close" : false })#"); httpService.addParam(type="body", value="#all_chunks[1]#"); var result = httpService.send().getPrefix(); if(structKeyExists(result.ResponseHeader, 'Status_Code') && result.ResponseHeader['Status_Code'] eq '200'){ upload_doc_session = deserializeJSON(result['filecontent'])['session_id']; }
      var stuResponse = {}; var httpService = new http(); httpService.setUrl("https://content.dropboxapi.com/2/files/upload_session/append_v2"); httpService.addParam(type="header", name="Dropbox-API-Arg", value="#serializeJSON({ "cursor" : { "session_id" : upload_doc_session, "offset" : max_chunk_size }, "close" : false })#"); httpService.addParam(type="body", value=""); var result = httpService.send().getPrefix(); if(structKeyExists(result.ResponseHeader, 'Status_Code') && result.ResponseHeader['Status_Code'] eq '200'){ } else{ here I get a 409 error that the first call is 8mb big. }

       

       

      When I dump "all_chunks[1]" it says it's 4mb length. Am I going a little mad here or am I just missing something?

      The weird part is that when I do a test with i.e. the string "test" in the first start session, then I correctly get the error

      that the last call was 4 bytes long. So I think maybe it's actually 8mb, but the java function len() gives 4mb...

      but that would be so weird.

    • DrunkenMoose's avatar
      DrunkenMoose
      Explorer | Level 3

      Hey,

       

      I posted a whole reply, but it get removed? But now I see that len(chunk) does not represent the correct bit length.

      You actually have to put the chunks in a ByteBuffer to correctly split it in the 4mb chunks. Weird how len(chunk)

      is exatly devided by 2, somehow this is actually 8mb. But thanks for the reply and the info! Now it's working great.

       

      Greetings,

      Moose

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        Thanks for following up. I'm glad to hear you already sorted this out. (Your other message got caught in the spam filter for some reason. I've restored it.)

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,910 PostsLatest Activity: 3 days ago
333 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!