cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 

download file API stopped working with 400 error

wind75423
Explorer | Level 3

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 1

Re: download file API stopped working with 400 error

Dropboxer
Dropboxer

[Cross-linking for reference: https://stackoverflow.com/questions/42755495/dropbox-download-file-api-stopped-working-with-400-erro... ]

 

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:

 

  1. You were passing the request options to the data parameter, instead of the config parameter of http.post.
  2. You weren't passing in valid JSON as the 'Dropbox-API-Arg' value.

 

 

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?