Discuss Dropbox Developer & API
Hi I am using the below endpoints to upload files in the backend.
https://content.dropboxapi.com/2/files/upload_session/start
After getting the session id, I run all on the finish batch endpoint
https://api.dropboxapi.com/2/files/upload_session/finish_batch_v2
However why am I getting this error ?
@feltj16 For reference, an "upload session" is a way to upload a large file by doing so in pieces. That is, each individual request would only contain one portion of the file. The "offset" of an upload session indicates how much of the file has been uploaded so far. (Also, if you only need to upload small file(s), you can just use /2/files/upload instead.)
An "incorrect_offset" error like that indicates that the app specified the wrong offset value, based on how much of the file the Dropbox API has received for that particular upload session so far.
For example, the error you shared in your first post indicates that the call failed because Dropbox had received 14 bytes for that upload session so far, but the app made a call where it supplied an offset other than 14.
Each upload session call should contain the binary data for the portion of the file that you want to upload, with the correct corresponding offset value.
And as Здравко, we do recommend using the official Dropbox JavaScript SDK if possible. That has corresponding methods for the HTTP endpoints, such as for upload sessions (as well as for the single small file upload). There are also examples of using the SDK to upload files, such as this simple example for uploading a small file from Node, as well as this more complex browser JavaScript example for upload small or large files.
Hi @feltj16,
It seems like your are messing offset on append content to least one of your files. I can say what exactly is your mistake, since there are different options, but you haven't clarified how exactly you are proceeding. You may have made additional mistakes (out of the error message direct scope). Post some piece of code showing what you are doing while the issue brings up. Can be strict sequence of HTTP requests (from the upload start) including all parameters/headers, but excluding/masking the access token in use.
@feltj16 wrote:... What does the body contents need to be in the start session? Is it just a url or binary data of the file ? ...
On upload of any kind (direct, session start, or append), only binary data can be send.
Hi @Здравко
This is some of my code, and the body that I am also not sure about ->
Hi again @feltj16,
In your code are 2 mistakes at least. 🙂 One directly represented with the error message and one's gonna get show when first error gets fixed.
Seems you are messing files content size.
@feltj16 wrote:...body: "What data is here ? base64 or file works ?"...var offset = filesize2[i];allfiles[i]["cursor"]["offset"] = Number(offset);...
Are you sure the body size matches to 'offset' you are setting for all files (currently set to string "What data is here ? base64 or file works ?" - 42 bytes)? 🧐 If you aren't certain, check this (print all 'offsets' out and actual content uploaded size).
Next, if you take a look on /2/files/upload_session/finish_batch_v2's documentation, there is a piece:
... UploadSessionStartArg.close or UploadSessionAppendArg.close needs to be true for the last upload_session/start or upload_session/append:2 call of each upload session. ...
Have you covered this requirement in you code? 🤔 Rhetoric of course. 🙂 This will be the next error message, if you don't fix it in advance! 😉
Hope this helps.
PS: By the way, why are you not using Dropbox JavaScript SDK? In such a way you will avoid to write something already available for reuse and focus on your code specific to the application your are building.
@feltj16 For reference, an "upload session" is a way to upload a large file by doing so in pieces. That is, each individual request would only contain one portion of the file. The "offset" of an upload session indicates how much of the file has been uploaded so far. (Also, if you only need to upload small file(s), you can just use /2/files/upload instead.)
An "incorrect_offset" error like that indicates that the app specified the wrong offset value, based on how much of the file the Dropbox API has received for that particular upload session so far.
For example, the error you shared in your first post indicates that the call failed because Dropbox had received 14 bytes for that upload session so far, but the app made a call where it supplied an offset other than 14.
Each upload session call should contain the binary data for the portion of the file that you want to upload, with the correct corresponding offset value.
And as Здравко, we do recommend using the official Dropbox JavaScript SDK if possible. That has corresponding methods for the HTTP endpoints, such as for upload sessions (as well as for the single small file upload). There are also examples of using the SDK to upload files, such as this simple example for uploading a small file from Node, as well as this more complex browser JavaScript example for upload small or large files.
Hi there!
If you need more help you can view your support options (expected response time for a 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!