cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
In need of some #MondayMotivation? Read more

File downloading issue - [Curl call doesn't return any error]

SOLVED
569 Views
11 Comments
0 Kudos
Highlighted

File downloading issue - [Curl call doesn't return any error]

Hi Everyone,

 

I am using CURL to download file from dropbox. Although the request is sent successfully and there is no error but it does't return the file information or contents. Can anyone tell what am I doing wrong.

 

Here is the PHP code snippet which I have using :

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://content.dropboxapi.com/2/files/download");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$headers = array();
$headers[] = "Authorization: Bearer token_value";
$headers[] = "Dropbox-Api-Arg: {\"path\": \"/Test_Folder/dropbox4.php\"}";
$headers[] = "Content-Type: ";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
else{
echo 'Success';
print_r($result);
}
curl_close ($ch);

 

1 Accepted solution

Accepted Solutions
Solution
Dropboxer

Re: File downloading issue - [Curl call doesn't return any error]

I just tried your code with my own token and a valid file path and it is printing out the file content.

You may want to try this example, which saves the file to disk and prints out the metadata:

https://stackoverflow.com/documentation/dropbox-api/408/downloading-a-file/20965/downloading-a-file-...
11 Replies
Super User II

Re: File downloading issue - [Curl call doesn't return any error]

Moved to API forum.

Dropboxer

Re: File downloading issue - [Curl call doesn't return any error]

What output are you getting? Based on your code, I would expect to see at least either 'Error' or 'Success'.

Re: File downloading issue - [Curl call doesn't return any error]

I do get Success when the code has executed which means that the request for file download was successful. However i dont get the file contents or file information in the response of curl execution.

Solution
Dropboxer

Re: File downloading issue - [Curl call doesn't return any error]

I just tried your code with my own token and a valid file path and it is printing out the file content.

You may want to try this example, which saves the file to disk and prints out the metadata:

https://stackoverflow.com/documentation/dropbox-api/408/downloading-a-file/20965/downloading-a-file-...

Re: File downloading issue - [Curl call doesn't return any error]

I followed the example and changed my code and it worked. It seems that other than code for saving file to system I had to change the header array a little. Thanks a lot Greg K.

Level 3

Re: File downloading issue - [Curl call doesn't return any error]

Hi Greg,

 

I am trying to download file from dropbox with below code. I am downloading file in my system's download folder

 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://content.dropboxapi.com/2/files/download");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$headers = array();
$headers[] = "Authorization: Bearer token_value";
$headers[] = "Dropbox-Api-Arg: {\"path\": \"$file\"}";
$headers[] = "Content-Type: ";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
else{
echo 'Success';
print_r($result);
}
curl_close ($ch);

 

The result shows me below error

Error in call to API function "files/download": The given OAuth 2 access token is malformed.Success1

 

Please help me to resolve this issue.

Level 3

Re: File downloading issue - [Curl call doesn't return any error]

Hi Greg,

 

Above solution is working fine for me. Now the only thing is I want to let user save the file in location they want and I also want to implement folder traverse functionality like dropbox uasing curl. Please help me in this

Level 3

Re: File downloading issue - [Curl call doesn't return any error]

Hi,

 

Using above code it is working fine for the files in root but I am facing issue downloading files in folder like /test/abc.png where I am facing below issue

 

Warning: fopen(test/abc.png): failed to open stream: No such file or directory.

 

Please help me to resolve this issue soon

Dropboxer

Re: File downloading issue - [Curl call doesn't return any error]

@krupal I'm glad to hear you already got that part working.

 

Exactly how you have the user select their desired local path for the downloaded file isn't related to the Dropbox API itself though, so I'm afraid I can't be of much help with that. For example, if you follow this example, you would set the local path via $out_filepath, but the UI for having the user select that path is up to you.

 

And if you want to be able to list out files and folders in Dropbox, you should use:

 

https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder

https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-continue

 

By the way, if you run in to any other issues, please open a new thread instead of replying here so we don't spam anyone else subscribed to this one.