cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Ross uses Dropbox to answer some new house questions 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: 

DBX JS SDK via Access Token not working for multiple users

DBX JS SDK via Access Token not working for multiple users

lightsage88
New member | Level 2

Hello,

 

I am trying to use the implementation discussed here so that anyone with the Access Token can upload files, etc. However, my team mates can not successfully upload files. Dropbox is being used as part of a Node backend and I want team mates, clients to be able to use just one access token so it's not too complicated.  Can you please help?

dropboxHelp.png

3 Replies 3

Re: DBX JS SDK via Access Token not working for multiple users

Greg-DB
Dropboxer

Can you elaborate on what you mean when you say they "can not successfully upload files"? Please show the rest of the relevant code you have implemented and whatever error/unexpected output you're getting.

Re: DBX JS SDK via Access Token not working for multiple users

lightsage88
New member | Level 2

Sure!

So I'm building a widget using Kendo for VUE/jQuery ((they are rather interchangeable between their many flavors)). This front-end component serves as a way for a user to access a particular drop box folder in my console-drop box-app. This is facilitated by a NodeJS back-end, which I've published some of the code for below.

 

class DropboxWidgetsService extends BaseService {
    constructor(stash, log) {
        super(stash, log);
        this.dbx = new Dropbox({ accessToken: process.env.DROPBOX_ACCESS_TOKEN });
    }
​
        async getDropboxFolderFiles(code, step) {
        try {
            let data = await this.dbx.filesListFolder(
                {
                    'path': `/magic-location/${code}/${step}`,
                    'recursive': true
                }
            );
            return data.result.entries.filter(el => el['.tag'] === 'file');
        } catch (error) {
            this.log.debug(error);
        }
    }

      async createDropboxWidgets(req, res) {
        try {
            let fileSaveLocation = __dirname.slice(0, __dirname.indexOf('services')) + 'temp';
            let magicalProjectCode = req.query.magicalProjectCode;
            let magicalProjectStep = req.query.magicalProjectStep.toUpperCase();
            console.log('projectStep', magicalProjectStep);
            let file = req.files[0];
            //TODO: We will want to include file type limiters based on the project step.
            let originalName = file.originalname;
            let buffer = file.buffer;
            let location = fileSaveLocation + '\\' + `${originalName}`;
            await fs.writeFile(location, buffer, async (err) => {
                if (err) {
                    this.log.debug(err);
                    return;
                }
                let response = await this.dbx.filesUpload({
                    path: `/Hogwarts/${magicalProjectCode}/${magicalProjectStep}/${file.originalname}`,
                    contents: fs.createReadStream(location)
                });
                await fs.unlink(location, (err) => {
                    if (err) {
                        console.error(err);
                        return;
                    }
                });
                res.json({status: response.status, path: response.result.path_lower});
            });
            
        } catch (error) {
            this.log.debug(error);
        }
    }
}

 

The latter method in the class doesn't work for anyone but me. I've shared my access token, app key and app secret. To my understanding, theoretically it should work, but my colleague (who has the same env variables as I do) just gets pending in their Network tab.

Re: DBX JS SDK via Access Token not working for multiple users

Greg-DB
Dropboxer

Thanks! So, if I understand correctly, it's the 'filesUpload' call that doesn't complete? For comparison, does the 'filesListFolder' call work successfully?

 

If so, how large is the file that they're trying to upload and how long are they waiting? If they're accidentally trying to upload a much larger file than intended, it may just be taking some time. Otherwise, if the call is actually not working, I would expect it to eventually timeout with some error.

 

Additionally, a bit more context on where/how this is running may be helpful. I understand this is running in a NodeJS back-end, but is that actually running on a server somewhere, the same for each of you, or are each of you running the code separately, e.g., on each of your own computers?

 

For reference, the 'filesUpload' method would make a connection to /2/files/upload on content.dropboxapi.com, whereas the 'filesListFolder' method would make a connection to /2/files/list_folder on api.dropboxapi.com. Might there be anything, such as a proxy, firewall, anti-virus, or other such software that may be interfering with the connection to content.dropboxapi.com?

 

(By the way, while it shouldn't cause a technical issue like this, access tokens aren't really meant to be shared. Each user is only supposed to have access to their own access token(s).)

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    lightsage88 New member | Level 2
What do Dropbox user levels mean?
Need more support?