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

varunpareek's avatar
varunpareek
Explorer | Level 3
28 days ago

getting error when trying to download a file via api in react native

const AccessAsync = await AsyncStorage.getItem('Access');
const ACCESS_TOKEN = AccessAsync;
const DESTINATION_PATH = `${RNFS.LibraryDirectoryPath}/Data.zip`;

try {
const response = await axios.post(
{
path: '/BnD_Data/', // Path to the folder you want to list files in
recursive: false, // Set to true if you want to list files recursively
},
{
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`, // Replace with your access token
'Content-Type': 'application/json',
},
}
);

if (response.status == 200) {
const filesInDropbox = []

response.data.entries.forEach(element => {
console.log(element.name)
filesInDropbox.push(element.name)
});

console.log(filesInDropbox)
const dataZipExists = filesInDropbox.includes("Data.zip");

if (dataZipExists) {
try {
const headers = {
Authorization: `Bearer ${ACCESS_TOKEN}`,
'Dropbox-API-Arg': JSON.stringify({
path: '/BnD_Data/Data.zip',
}),
'Content-Type': 'application/octet-stream'
};

const response = await RNFetchBlob.config({
path: DESTINATION_PATH,
}).fetch('POST', DOWNLOAD_URL, headers);
} catch (error) {

}
}
}
} catch (error) {

}



this is my code where i try to download file using api but in this issue is if i upload file and then i try to download then file is being download but when second time i try to download file then getting error continuously until i re upload the same file and then download "error: [Error: The operation couldn’t be completed. Protocol error] " what's this issue

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    I see you're getting an error "The operation couldn’t be completed. Protocol error". This is not actually an error from Dropbox itself, so unfortunately we can't offer much insight on that. It looks like it may be an issue with your network connection/stack, so you may need to refer to the support resources for the platform you're using.

    • varunpareek's avatar
      varunpareek
      Explorer | Level 3

      First of all thanks for your reply. now i want to ask how it's possible when i upload any file on drop box using api, after that if i use this code then it's working fine and when i try this for second time it's showing error how it's possible. is there any issue with my code?

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        It's not clear from this code what the issue may be. It seems like it may be a problem with the platform or network client itself.