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
filesUploadSessionFinishBatchCheck(). However, this is something that I should know before calling the filesUploadSessionFinishBatchCheck() so that I can pass it down