Dropbox CORS 无法下载文件
Dropbox CORS cannot download file
我正在按照本指南进行操作https://dropbox.github.io/dropbox-api-v2-explorer/#files_download_zip
我在使用 api 保管箱时遇到问题,想获取下载文件。
首先是关于cors的问题。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/download_zip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Authorization: Bearer myTokenAcess';
$headers[] = 'Dropbox-Api-Arg: {\"path\":\"/myfolder/mysubfolder/mysubfolderagain\"}';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
结果是
Error in call to API function "files/download": Bad HTTP
"Content-Type" header: "application/x-www-form-urlencoded". Expecting
one of "text/plain", "text/plain; charset=utf-8",
"application/octet-stream", "application/octet-stream; charset=utf-8".
然后我尝试在页眉中添加这一行
$headers[] = 'Content-Type: application/octet-stream';
结果是
Error in call to API function "files/download": HTTP header
"Dropbox-API-Arg": could not decode input as JSON
然后我试图将 drobox-api-arg
行更改为
$headers[] = 'Dropbox-Api-Arg: json_decode({\"path\":\"/myfolder/mysubfolder/mysubfolderagain\"},TRUE)';
结果还是和上面一样
Error in call to API function "files/download": HTTP header
"Dropbox-API-Arg": could not decode input as JSON
有人可以帮我解决这个问题吗?
更新:
@sideshowbarker 结果使用这个
$headers[] = 'Dropbox-Api-Arg: {"path":"/myfolder/mysubfolder/mysubfolderagain"}'
我根据@sideshowbarker 的说法找到了答案。我只需要将字节转换为 zip
所以我只是在最后一行添加这一行,现在工作正常。
foreach($result as $byte)
{
$byteString .= $byte;
}
header("Content-type: application/zip");
header("Content-Disposition: inline; filename=tesFolderQ.zip");
echo $byteString;
我正在按照本指南进行操作https://dropbox.github.io/dropbox-api-v2-explorer/#files_download_zip
我在使用 api 保管箱时遇到问题,想获取下载文件。 首先是关于cors的问题。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/download_zip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Authorization: Bearer myTokenAcess';
$headers[] = 'Dropbox-Api-Arg: {\"path\":\"/myfolder/mysubfolder/mysubfolderagain\"}';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
结果是
Error in call to API function "files/download": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded". Expecting one of "text/plain", "text/plain; charset=utf-8", "application/octet-stream", "application/octet-stream; charset=utf-8".
然后我尝试在页眉中添加这一行
$headers[] = 'Content-Type: application/octet-stream';
结果是
Error in call to API function "files/download": HTTP header "Dropbox-API-Arg": could not decode input as JSON
然后我试图将 drobox-api-arg
行更改为
$headers[] = 'Dropbox-Api-Arg: json_decode({\"path\":\"/myfolder/mysubfolder/mysubfolderagain\"},TRUE)';
结果还是和上面一样
Error in call to API function "files/download": HTTP header "Dropbox-API-Arg": could not decode input as JSON
有人可以帮我解决这个问题吗?
更新: @sideshowbarker 结果使用这个
$headers[] = 'Dropbox-Api-Arg: {"path":"/myfolder/mysubfolder/mysubfolderagain"}'
我根据@sideshowbarker 的说法找到了答案。我只需要将字节转换为 zip 所以我只是在最后一行添加这一行,现在工作正常。
foreach($result as $byte)
{
$byteString .= $byte;
}
header("Content-type: application/zip");
header("Content-Disposition: inline; filename=tesFolderQ.zip");
echo $byteString;