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

Forum Discussion

amei's avatar
amei
Explorer | Level 3
4 months ago

Using javascript to download file from dropbox

I am creating a javascript routine that requires me to download and upload updated files in my dropbox app file folders which contains updated football picks. I am able to upload files to my app but when I try to upload I get an undefined error. 

file path :

download functions (I tried both of these) :

Both of these functions return the same error :

Any assistance would be greatly appreciated. Thanks. 

14 Replies

  • amei's avatar
    amei
    Explorer | Level 3
    4 months ago

    I updated my download function as :

    I get a successful download, but I don't see the one line of football picks, just a blank array. The array is formatted correctly, but does not contain any information. 

    I changed fileBinary to fileText. I'm not sure if I have to define that it is a json file. 

  • amei's avatar
    amei
    Explorer | Level 3
    4 months ago

    thanks for your assistance. I updated both functions as you suggested :

    Still getting the same errors :

    The jason file that I have uploaded from my upload function looks like this :

    It is an array of football picks. So when I upload the files I used the JSON.stringify to save the array. When I open the jason file I see text, not binary characters. Not sure if this is the problem. Perhaps a text response would ? I need to download the file back into the array (what the file is currently saved as as shown above. 

    I should have included this info in my initial post. I hope this provides more clarity. thanks. 

  • DB-Des's avatar
    DB-Des
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    4 months ago

    Hi amei​ 

    The response from 'filesDownload()' does not contain a 'fileBlob' property (which is why you are getting an 'undefined' in the error message). The response contains a 'fileBinary', which can be accessed as such: 'response.result.fileBinary'. Additionally, you can convert the returned Buffer to text or a string by invoking the 'toString()' method on the response. We would also recommend making that callback function an async function:

    ...
    dbx.filesDownload({ path: dropbox_users_path_file })
    .then(async (response) => {
      console.log(response.result.fileBinary.toString())
    }
    ...

    Similarly for the second function:

    ...
    try {
      const response = await dbx.filesDownload({
        path: dropbox_users_path_file
      })
      console.log(response.result.fileBinary.toString())
    }
    ...

    In order to further assist with the file upload error, please provide the code snippet used to upload files to Dropbox. The screenshots provided are both for downloading files ('filesDownload()').

  • amei's avatar
    amei
    Explorer | Level 3
    4 months ago

    LoadFileFromDropbox error (other load function attempt)

     

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API
Make connections with 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!