0

I have a file on device locally. I want to upload this file to Dropbox. Almost all is done, but I cannot figure out what should be the value of the contents property of the object? I am using cordova file plugin to get the file url and Dropbox SDK for uploading. Here's the code. Lets say i want to upload an MP3 or a ZIP file...

let dbx = new Dropbox({ clientId: CLIENT_ID })
dbx.filesUpload({
            path: "/" + fileName,
            contents: XXXXXXXX, // what should be the value of this?
            mode: "overwrite",
            mute: true,
            autorename: false,
            strict_conflict: false
        })
            .then(response => { 
                 // do something with success
        })
            .catch(error => {
                // do something with error
        })
Devashish
  • 1,260
  • 1
  • 10
  • 21
  • You should pass the actual file data that you want to upload to the `contents` parameter. There's [an example here for node](https://github.com/dropbox/dropbox-sdk-js/blob/b2353edeb221ec17b8e70a1d8fd4799e2f1f031d/examples/javascript/node/upload.js#L23), for instance. – Greg Jun 12 '19 at 18:15
  • @Greg thanks for the link Greg. However, I am not sure whether to read the file as as Array Buffer or as a dataURI would be better? Also, won't these methods be memory intensive and make the app/device slow, especially when uploading big files like 150mb or so? And yet another thing is whether the file will be "openable" as it was originally? Example: If I read a .zip file using one of the methods and then download the file later, will it still open as ZIP? – Devashish Jun 12 '19 at 18:19
  • I see you opened a new question for these, so I'll try to offer some help there: https://stackoverflow.com/questions/56575928/how-to-upload-a-file-to-dropbox-using-js-sdk/56583287#56583287 – Greg Jun 13 '19 at 14:55

0 Answers0