Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
I am new to using php and dropbox, so this query may seem simple.
My application is to integrate the ability to upload/download to a specified folder in my Dropbox.
I can do the following in php (with the help of CodeCourse)
I am struggling with how to download a file to my PC and save it.
Code snippet:
require_once "./dropbox-sdk/Dropbox/autoload.php";
$children = $client->getMetadataWithChildren($path);
$docs = $children["contents"];
# from the $docs array I can get the path to the required file
# I then try
$outStream ='';
$download = $client->getFile($path,$outStream);
header("Content-type: " . $download["mime"]);
echo $download["data"];
exit;
I think the headers may need to be improved but the first problem is that the getFile function errors as I am not initialising $outStream correctly.
Any help would be appreciated
It looks like you're using the Dropbox PHP Core SDK. The tutorial for that covers downloading a file using the getFile method here:
https://www.dropbox.com/developers-v1/core/start/php#downloading
Thank you , I had seen this but discounted it as it stores on my web server , whereas i really it want it served to my browser where the user can save to local disk ?
In that case, you essentially have two options:
1) Use getFile to get the file content and pass it down to the browser instead of saving it to disk. You'll still need to supply a valid resource as the $outStream parameter where the SDK can write the data though. How exactly you set that up it outside the scope of Dropbox API support, and may depend on your web framework, so I can't offer much insight there.
2) If you don't want to pass the data through your server, use createShareableLink or createTemporaryDirectLink to get a link to the file to give to the user in their browser.
In case this might be of help to others, I decided to use the sdk suggested route and save to web server using a temp file, which I create with a new stream for the getFile method. After downloading the file I then clear the file.
thanks.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!