问题
I'm developing a web application using PHP, Dropbox API and Box API. I already have an access token to use these API.
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
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);
?>
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.
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?
I only need to add this Authorization header but it makes me crazy...
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
回答1:
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.
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
来源:https://stackoverflow.com/questions/28411904/dropbox-box-api-direct-download-file-with-access-token