I want to download the folder in my dropbox as a zip file. I am using JavaScript SDK. I know there's filesDownloadZip() available for that.
I am able to get the Binary data from API, But still unable to download the file.
I am using Node/Express Server and React on front-end.
Here's my Backend code that's interacting with api:
const downloadZip = async (req, res) => {
/**
* folder_id: String
* team_member_id: String <Id of the member who shared the folder>
*/
try{
if(!req.body.folder_id)
return res.status(400).json({error: "This endpoint expects folder_id to be passed."});
if(!req.body.team_member_id)
return res.status(400).json({error: "This endpoint expects team_member_id to be passed."});
const { dbxUser } = req;
const { folder_id } = req.body;
const data = await dbxUser.filesDownloadZip({path: folder_id})
res.status(200).json({data});
} catch(error) {
console.log(error)
res.status(500).json({
error
});
}
}
And Here's my Front-end code:
onDownloadBtnClick = async () => {
try{
const { folder_id, shared_by: team_member_id } = this.state.data;
const { data } = await axios.post(`${sharedRoute}/downloadZip`, {folder_id, team_member_id});
window.open(JSON.stringify(data.fileBinary));
} catch(error){
console.error(error)
}
}
I've also posted this question on StackOverflow https://stackoverflow.com/questions/57024827/how-to-download-file-from-buffer-stored-in-json-object
How can I download the zip file out of this data?