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
tiamat
4 years agoHelpful | Level 6
no longer able to upload video via api
The following code once successfully uploaded video, but now does not. No errors thrown on execution of the upload() function and I get 200 a response back from the server for each chunk read from the file. I wonder if there is something wrong with my account - I got a warning to renew and afterwards I started having issues? Thanks much for your help.
const fs = require('fs');
const path = require('path');
const { dbx } = require('../dropbox/dbx');
const MAX_RETRIES = 100;
const CHUNK_SIZE = 10485760;
const uploadBigFile = async (localPath, uploadPath, size) => {
const stream = fs.createReadStream(localPath, {
highWaterMark: CHUNK_SIZE,
});
let chunkNumber = 0;
let offset = 0;
let session_id;
for await (let chunk of stream) {
if (!chunkNumber++) {
const { result } = await dbx.filesUploadSessionStart({
contents: chunk,
});
session_id = result.session_id;
} else if (offset + chunk.length === size) {
await dbx.filesUploadSessionFinish({
contents: chunk,
cursor: { session_id, offset },
commit: {
path: uploadPath,
mode: 'overwrite',
client_modified: date,
},
});
} else {
await dbx.filesUploadSessionAppendV2({
contents: chunk,
cursor: { offset, session_id },
close: false,
});
}
offset += chunk.length;
}
};
const upload = ({ futureDropboxFileName, date }) => {
return new Promise(async (resolve, reject) => {
async function doUpload(futureDropboxFileName, date, photo, retries = 0) {
const dropboxPath = `${process.env.DROPBOX_FOLDER}${futureDropboxFileName}`;
const convertedPath = path.join(__dirname, '/tmp/', futureDropboxFileName);
try {
const { size } = fs.statSync(convertedPath);
await uploadBigFile(convertedPath, dropboxPath, date, size);
resolve('ok');
} catch (error) {
if (retries <= MAX_RETRIES) {
doUpload(futureDropboxFileName, date, photo, retries + 1);
} else {
return reject(error);
}
}
}
return doUpload(futureDropboxFileName, date, photo);
});
};
Thanks, you clued me into a bug that got into my code. 🙂
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,912 PostsLatest Activity: 4 hours agoIf 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!