cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lookup Failed Error from Finish Batch

Lookup Failed Error from Finish Batch

feltj16
Explorer | Level 4
Go to solution

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 ? 

"body": "{"entries": [{".tag": "failure", "failure": {".tag": "lookup_failed", "lookup_failed": {".tag": "incorrect_offset", "correct_offset": 14}}}]}",
 
I am using Nodejs. What does the body contents need to be in the start session? Is it just a url or binary data of the file ? 
 
Any Help ?
Thank you.

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

@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.

View solution in original post

4 Replies 4

Здравко
Legendary | Level 20
Go to solution

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.

feltj16
Explorer | Level 4
Go to solution

Hi @Здравко

 

This is some of my code, and the body that I am also not sure about ->

 

var file = folder+"/"+data
var promises = [];
var allfiles = [];
var UPLOAD_FILE_SIZE_LIMIT = 500 * 1024 * 1024;
 
async function uploadFile5(listfiles)
{
var totalfiles = listfiles.length;

for (let i = 0; i < totalfiles; i++)
{
if (filename2[i])
{
var file64a = file64b[i];
var settings = {
'method': 'POST',
'encoding': 'binary',
'headers': {
'Content-Type': 'application/octet-stream',
'Dropbox-API-Select-User': 'xxxxxx',
'Dropbox-API-Path-Root': '{".tag": "namespace_id", "namespace_id": "xxxxxxx"}',
'Authorization': 'Bearer XXXXXXXXX',
'Dropbox-API-Arg': '{"close":true}'
},
body: "What data is here ? base64 or file works ?"

};

var obj = context.request(settings);
var str = JSON.stringify(obj);
var pars = JSON.parse(str);

allfiles[i] = new Object();
allfiles[i]["cursor"] = new Object();

allfiles[i]["cursor"]["session_id"] = pars.body.session_id;

var offset = filesize2[i];
allfiles[i]["cursor"]["offset"] = Number(offset);
allfiles[i]["commit"] = new Object();
allfiles[i]["commit"]["path"] = folder+"/"+filename2[i].trim();

allfiles[i]["commit"]["mode"] = "add";
allfiles[i]["commit"]["strict_conflict"] = false;
allfiles[i]["commit"]["autorename"] = true;

//promises.push(doFilesAsync(allfiles,i));
}

}



}

uploadFile5(sfiles2);
var entriesobj = new Object();
entriesobj["entries"] = allfiles;
var entriesobj2 = JSON.stringify(entriesobj);

var settings2 = {
'method': 'POST',
'headers': {
'Content-Type': 'application/json',
'Dropbox-API-Select-User': 'xxxxxx',
'Dropbox-API-Path-Root': '{".tag": "namespace_id", "namespace_id": "xxxxx"}',
'Authorization': 'Bearer XXXXXXXXXX'
},
body: entriesobj2
};

var obj2 = context.request(settings2);
ret2 = JSON.stringify(obj2);
 
Thank you...
 

Здравко
Legendary | Level 20
Go to solution

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.

Greg-DB
Dropbox Staff
Go to solution

@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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    feltj16 Explorer | Level 4
What do Dropbox user levels mean?