Dropbox下载文件API停止工作并出现400错误 [英] Dropbox download file API stopped working with 400 error
问题描述
我使用dropbox下载文件API,但获得了令牌,但返回400错误的请求错误
调用API函数文件/下载时出错:必须提供HTTP标头授权或URL参数授权
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"
我遵循dropbox api doc,但无法正常工作〜〜
我该如何解决?
I follow dropbox api doc , but it cannot work ~""~ How do I fix it ?
这是我的代码(angular2)
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 })
};
});
推荐答案
我在android中使用了dropbox v2 api。和您一样,我收到了400个错误的请求。事实证明,Android HttpUrlConnection设置了默认的 Content-Type标头值。 Dropbox下载API要求 Content-Type丢失或为空。我在iOS中没有相同的问题。
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.
所以也许在angular2中,您需要执行以下操作:
So maybe in angular2, you need to do something like:
headers.append('Content-Type','');
Dropbox-API-Arg标头也必须像这样:
Also the 'Dropbox-API-Arg' header need to be like:
headers.append('Dropbox-API-Arg','{\"path\": \"/filepath\"}');
这篇关于Dropbox下载文件API停止工作并出现400错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!