0

I use dropbox download file API , and i got a token , but it's return 400 bad request error "Error in call to API function "files/download": Must provide HTTP header "Authorization" or URL parameter "authorization"

I follow dropbox api doc , but it cannot work ~""~ 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 })
  };
});
shaochuancs
  • 15,342
  • 3
  • 54
  • 62
steven
  • 45
  • 7
  • Why are you using `Bearer` in your Authorization token? – Ajk_P Mar 13 '17 at 02:09
  • I follow dropbox api doc , it's need use Bearer https://www.dropbox.com/developers/documentation/http/documentation#files-download – steven Mar 13 '17 at 04:14
  • [Cross-linking for reference: https://www.dropboxforum.com/t5/API-support/download-file-API-stopped-working-with-400-error/m-p/211317#M10617 ] – Greg Mar 13 '17 at 18:31

1 Answers1

3

I use dropbox v2 api in android. Just as you, I got 400 bad request. It turns out that Android HttpUrlConnection set a default "Content-Type" header value. And dropbox download api require "Content-Type" to be missing or empty. I don't have same issue in iOS though.

So maybe in angular2, you need to do something like:

headers.append('Content-Type','');

Also the 'Dropbox-API-Arg' header need to be like:

headers.append('Dropbox-API-Arg','{\"path\": \"/filepath\"}');
Alex Bin Zhao
  • 398
  • 3
  • 11