Dropbox download file API stopped working with 400 error

删除回忆录丶 提交于 2019-12-13 06:18:13

问题


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 })
  };
});

回答1:


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\"}');


来源:https://stackoverflow.com/questions/42755495/dropbox-download-file-api-stopped-working-with-400-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!