Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

chartbid's avatar
chartbid
Explorer | Level 3
9 years ago

Dropbox JavaScript SDK - ReferenceError: Dropbox is not defined (with angularJS 1.4)

Hi,

I'm trying to use Dropbox Javascript SDK (version 2) in my angular 1.4 Application.

The installation of the package was OK but when I execute the function 'viewFile' I get an error ReferenceError: Dropbox is not defined  in the 2nd line:  var dbx = new Dropbox({ accessToken: ACCESS_TOKEN });

 

You can see the function:

 

function viewFile() {
            var SHARED_LINK = "/" + vm.selectedDoc.url;
            var dbx = new Dropbox({ accessToken: ACCESS_TOKEN });
            
            dbx.sharingGetSharedLinkFile({url: SHARED_LINK})
                .then(function(data) {
                    var downloadUrl = URL.createObjectURL(data.fileBlob);
                    var downloadButton = document.createElement('a');
                    downloadButton.setAttribute('href', downloadUrl);
                    downloadButton.setAttribute('download', data.name);
                    downloadButton.setAttribute('class', 'button');
                    downloadButton.innerText = 'Download: ' + data.name;
                    document.getElementById('results').appendChild(downloadButton);
                })
                .catch(function(error) {
                    console.error(error);
            });
            return false;
        }

Keep in mind that I don´t use TypeScript in the App

 

How Can I solve this error?

 

Thanks in advance.

4 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago
    How are you importing 'Dropbox'? Do you get any errors before the ReferenceError?
  • chartbid's avatar
    chartbid
    Explorer | Level 3
    9 years ago

    Good morning Greg,

    No, I don't get any error before the ReferenceError.

     

    I've noticed that it's necessary to use

     

    var Dropbox = require('dropbox');

    before creating the Dropbox object.

    In that case I think I have to install RequireJS module in my angularJS 1.4 app.

    Is this the way that I'll fix the problem or is there any other easier solution?

     

    Thanks in advance.

     

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago
    Thanks for following up. I'm glad to hear you got this working. The JavaScript SDK wasn't built for Angular unfortunately, so I can't offer a more official/supported solution.
  • hamadafadil's avatar
    hamadafadil
    New member | Level 2
    8 years ago

    Try:

    var Dropbox = require('dropbox').Dropbox;

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If 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, Facebook or Instagram.

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!