cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: 

axios downloaded an mp3 file from dropbox api is empty, 0 bytes in react native

axios downloaded an mp3 file from dropbox api is empty, 0 bytes in react native

Mert
New member | Level 2

getmedia(medianame) {
console.log(medianame);
path1 = RNFS.DocumentDirectoryPath + '/' + medianame;
console.log(path1);
axios({

method: 'POST',
url: 'https://content.dropboxapi.com/2/files/download',
headers: {
Authorization: 'Bearer JxxxxxxxxxxC7JnnYdLgKrxxyxyxyxyxyyxyxyxeeee',
'Dropbox-API-Arg': '{ "path": "/Apps/Myapp/+ medianame" }',
'Content-Type': 'text/plain',
Host: 'content.dropboxapi.com'
}

})
.then((response) => {
console.log(response);
RNFS.writeFile(path1, response, 'utf8')
.then((success) => {
console.log('FILE WRITTEN!');
})
.catch((err) => {
console.log(err.message);
});
});
}

I am using axios with post method to download an mp3 file from dropbox and ı write the response to the app folder but in app folder file seems to have 0 bytes, empty. What might be the problem?

1 Reply 1

Greg-DB
Dropbox Staff

The /2/files/download endpoint is the right endpoint for downloading file data. If the call is successful, the response body will be the file data. There are a number of ways for the call to fail though, e.g., if the path you provide is incorrect.

It looks like you're not catching any potential errors on the /2/files/download call. You should add a catch to Dropbox API call itself (similar to the one you have for the local file writing operation). That way, you can detect when the call fails.

For instance, looking at your code, it looks like you may be supplying the wrong path value. When using an app with the "app folder" permission, you shouldn't explicitly include the "/Apps/Myapp" portion in your file paths. That part is automatically assumed for you. So, if you're trying to access a file at "/Apps/Myapp/file.ext" with the app for that app folder, you should just supply "/file.ext".

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?