We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
wind75423
9 years agoExplorer | Level 3
download file API stopped working with 400 error
I use download file API , and i got a token , but it's return 400 bea request error
"Error in call to API function "files/download": Must provide HTTP header "Authorization" or URL parameter "authorization"
How do I fix it ?
this is my code ( angular2 )
downloadFile(fileid){ let headers = new Headers(); headers.append('Authorization', 'Bearer ' + this.accessToken); headers.append('Dropbox-API-Arg','path:'+ fileid); return this.http.post('https://content.dropboxapi.com/2/files/download',new RequestOptions({ headers: headers ,responseType:ResponseContentType.ArrayBuffer})).map((res) => { let arrayBuffer = res.arrayBuffer(); let contentType = res.headers.get('content-type'); return { fileid: fileid, blob: new Blob([arrayBuffer], { type: contentType }) }; });
1 Reply
- Greg-DB9 years ago
Dropbox Community Moderator
[Cross-linking for reference: https://stackoverflow.com/questions/42755495/dropbox-download-file-api-stopped-working-with-400-error ]
The error message is indicating that the access token isn't being supplied with the request properly. I can't offer much help with using the HTTP client in Angular, but here's a simplified version that works for me:
let headers = new Headers(); headers.append('Authorization', 'Bearer <ACCESS_TOKEN>'); headers.append('Dropbox-API-Arg','{"path": "/test.txt"}'); console.log(headers); http.post('https://content.dropboxapi.com/2/files/download', null, new RequestOptions( { headers: headers, responseType: ResponseContentType.ArrayBuffer} ) ) .subscribe((res) => {console.log(res)});
There were two main options:
- You were passing the request options to the data parameter, instead of the config parameter of http.post.
- You weren't passing in valid JSON as the 'Dropbox-API-Arg' value.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 2 days ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!