cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We love to hear how every person gets the most from Dropbox, and it seems everyone has a slightly different use for it - tell us yours here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

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

no longer able to upload video via api

no longer able to upload video via api

tiamat
Helpful | Level 6

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);
  });
};

 

 

1 Accepted Solution

Accepted Solutions

Re: no longer able to upload video via api

tiamat
Helpful | Level 6

Thanks, you clued me into a bug that got into my code. 🙂

View solution in original post

2 Replies 2

Re: no longer able to upload video via api

Greg-DB
Dropboxer

Can you print out the result of filesUploadSessionFinish? If no exceptions are being thrown, that should be returning the metadata of the uploaded file.

Re: no longer able to upload video via api

tiamat
Helpful | Level 6

Thanks, you clued me into a bug that got into my code. 🙂

View solution in original post

Who's talking

Top contributors to this post

  • User avatar
    tiamat Helpful | Level 6
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?