You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

Sega's avatar
Sega
New member | Level 2
7 years ago

filesUpload gives corrupted file

Hello,   I'm want to use the Dropbox API/SDK in one of my projects. I have to convert a base64 string I'm getting from my webcam as a screenshot into a real image and then upload it to Dropbox. (I'...
  • Greg-DB's avatar
    7 years ago

    I believe you should just supply the buffer directly, so all you need to do is:

     

    const base64File = this.webcam.getScreenshot()
    const dbx = new Dropbox({ accessToken: this.state.dropboxToken })
    const i = base64File.indexOf('base64,')
    const buffer = Buffer.from(base64File.slice(i + 7), 'base64')
    const name = 'test.png'
    
    dbx.filesUpload({path: '/' + name, contents: buffer})
    .then(function (response) {
        console.log(response)
    })
    .catch(function (error) {
        console.error('dropbox error', error)
    })