Discuss Dropbox Developer & API
Hi, I am trying to upload many files using the JavaScript SDK's
const uploadImagesToDropbox = async (team_member_id, dbxUser, clientFolder) => { try{ const queueData = await uploadQueue.find({team_member_id, status: 2}) const appDir = path.dirname(require.main.filename); const printResPath = `${clientFolder}/Print Resolution`; const webResPath = `${clientFolder}/Web Resolution`; const isPrintResPathExists = await dbxFolderExists(dbxUser, printResPath); const isWebResPathExists = await dbxFolderExists(dbxUser, webResPath); !isPrintResPathExists && await dbxUser.filesCreateFolderV2({path: printResPath}) !isWebResPathExists && await dbxUser.filesCreateFolderV2({path: webResPath}); const batchData= []; for(let data of queueData){ let PrintResFilePath = `${appDir}${data.destination.split("/").join("\\")}\\${data.filename}`; let WebResFilePath = `${appDir}${data.destination.split("/").join("\\")}\\Web_Resolution\\${data.filename}`; let PrintResFile = fs.readFileSync(PrintResFilePath) let WebResFile = fs.readFileSync(WebResFilePath) const printResStart = await dbxUser.filesUploadSessionStart({ contents: PrintResFile, close: true}) const webResStart = await dbxUser.filesUploadSessionStart({ contents: WebResFile, close: true}) batchData.push({ cursor:{ session_id: printResStart.session_id, offset: 0 //<--- What should I pass Here? }, commit: { path: printResPath } }) batchData.push({ cursor:{ session_id: webResStart.session_id, offset: 0 //<--- What should I pass Here? }, commit: { path: webResPath } }) console.log(data.filename, "Uploaded") }console.log(batchData) const res = await dbxUser.filesUploadSessionFinishBatch({ entries: batchData }); console.log(res) const status = await dbxUser.filesUploadSessionFinishBatchCheck({async_job_id: res.async_job_id}) console.log(JSON.stringify(status)) let interval = setInterval(async () => { const status = await dbxUser.filesUploadSessionFinishBatchCheck({async_job_id: res.async_job_id}) status['.tag'] === "complete" && clearInterval(interval) console.log(JSON.stringify(status)) }, 10000); await uploadQueue.deleteMany({team_member_id}) rimraf.sync(`${appDir}\\uploads\\${team_member_id.replace(":", "_")}`) } catch(error){ console.log(error) return error; } }Currently, this code throws the following error
{ ".tag": "complete", "entries": [ { ".tag": "failure", "failure": { ".tag": "lookup_failed", "lookup_failed": { ".tag": "incorrect_offset", "correct_offset": 11721555 } } }, { ".tag": "failure", "failure": { ".tag": "lookup_failed", "lookup_failed": { ".tag": "incorrect_offset", "correct_offset": 3529761 } } }, { ".tag": "failure", "failure": { ".tag": "lookup_failed", "lookup_failed": { ".tag": "incorrect_offset", "correct_offset": 8843127 } } }, { ".tag": "failure", "failure": { ".tag": "lookup_failed", "lookup_failed": { ".tag": "incorrect_offset", "correct_offset": 2877230 } } }, { ".tag": "failure", "failure": { ".tag": "lookup_failed", "lookup_failed": { ".tag": "incorrect_offset", "correct_offset": 10066923 } } }, { ".tag": "failure", "failure": { ".tag": "lookup_failed", "lookup_failed": { ".tag": "incorrect_offset", "correct_offset": 3037603 } } } ] }I know there's a correct_offset value, but I received it after calling
You should keep track of the offset client-side, while uploading the data, so that you can specify the value when sending the next piece of the file, or when finishing the file. There's a sample implementation here.
It looks like your usage is a little different though, in that you're not using filesUploadSessionAppendV2. It sounds like your files are small enough that you can upload all of the data with a single call to filesUploadSessionStart each. In this case, that means that your "offset" would just be the length of the file data.
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!