带有访问令牌的Dropbox / Box API直接下载文件 [英] Dropbox / Box API direct download file with access token

查看:110
本文介绍了带有访问令牌的Dropbox / Box API直接下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP,Dropbox API和Box API开发Web应用程序。
我已经具有使用这些API的访问令牌。

I'm developing a web application using PHP, Dropbox API and Box API. I already have an access token to use these API.

我的需要是:
1.直接从Dropbox / Box服务器$下载文件b $ b 2.无需在浏览器中进行用户认证
3.无需共享DropBox / Box上的文件

My needs are : 1. Download a file directly from Dropbox / Box server 2. Without being user authenticated in the browser 3. Without having to share the file on DropBox / Box

实际上,我有一个PHP脚本在我的服务器上,它通过授权标头传递了带有访问令牌的文件url上的Curl。它可以工作,但在大文件上,由于内存限制,我的脚本失败了(当用户在浏览器中下载文件时,Curl将文件存储在内存中)。

Actually, I have a PHP script on my server that make a Curl on the file url with the access token passed throught the Authorization header. It works but on big files, my script failed due to memory limit (Curl is storing the file in memory while the user is downloading the file in his browser).

<?php
header("Content-Type: application/octet-stream; charset=UTF-8");
header('Content-Disposition: attachment;filename="' . $filename . '";filename*=UTF-8\'\'' . urlencode($filename));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $downloadUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token));
curl_exec($ch);
curl_close($ch);
?>

出于某些隐私原因,我无法在网络服务器上存储临时文件。
出于某些用户友好的原因,我不想使用Ajax请求下载文件。

For some privacy reasons, I can't store temporary files on my webserver. For some userfriendly reasons, I don't want to download the file with Ajax request.

我在Dropbox和Box API中搜索了直接下载链接但似乎什么都没有...

I have searched for a direct download link in Dropbox and Box API but it seems that nothing is available...

我可以尝试什么解决方案?

What solutions can I try?

我只需要添加此Authorization标头,但这会让我发疯...

I only need to add this Authorization header but it makes me crazy...

注意:
对于Google云端硬盘,我们可以直接在文件下载网址中传递访问令牌,因此效果很好。
对于OneDrive,Microsoft提供了直接下载链接

Note: For Google Drive, we can pass the access token directly in the file download url so it works great. For OneDrive, Microsoft give us a direct download link

推荐答案

作为参考,至少使用Dropbox可以通过URL参数 access_token中的访问令牌,而不是Authorization标头中的访问令牌。

For reference, with Dropbox at least, you can pass the access token in a URL parameter "access_token" as opposed to in the Authorization header.

此外,在需要直接下载链接但无法提供的情况下访问令牌,您可以使用/ media返回的URL:

Also, in a situation where you need a direct download link but can't supply the access token, you can use the URL returned by /media:

https://www.dropbox.com/developers/core/docs#media

这篇关于带有访问令牌的Dropbox / Box API直接下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆