cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
TCB Level 2
Level 2

File download using v2 in PHP

Hello,

Am trying to download file from dropbox using dropbox api-PHP.

I have a sharelink generated using dropbox api

$dropbox->postToAPI

is "https://www.dropbox.com/s/bs69w68dwoiiu2q/img0007cade2gtw.jpg?raw=1".

Am not able to download file from dropbox using

$dropbox->download(url);

 

2 Replies
Dropboxer

Re: File download using v2 in PHP

Note that Dropbox does not have an officially supported SDK in PHP, so if you have any SDK specific questions, you will need to ask the developer who authored the SDK. 

It appears that you might be using the "kunalvarma05/dropbox-php-sdk".  If that is the case, I suggest reading their wiki page on Uploading and Downloading files (https://github.com/kunalvarma05/dropbox-php-sdk/wiki/Upload-and-Download-Files) as it has some helpful examples.

Looking at your example, there are two ways you can possibly solve your problem.

1)  Because you have already created a shared link with the API, you do not need to use the "download()" method.  The link you have posted above can be downloaded with any PHP library or function for accessing a URL on the web.  The file_get_contents() (http://php.net/manual/en/function.file-get-contents.php) method appears to be a very commonly used approach for downloading a file with a url.

2) Downloading a file does not require creating a shared link first.  If you know the path of the file you wish to download, you can use the path of the file within Dropbox to download directly. Assuming you are using the "kunalvarma05/dropbox-php-sdk", the usage would be:

$dropbox->download(<path of file in dropbox>, <path to save locally>)
Reply
Loading...
Highlighted
Dropboxer

Re: File download using v2 in PHP

A third possible solution would be to use the sharing/get_shared_link_file API method.  This takes a "url" parameter that would match the shared link URL in your original post, and will return the raw bytes of the file referenced by the shared link.  This approach would be similar to my suggestion #1 in my previous reply.

Reply
Loading...