cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issue with cURL using https://api.dropboxapi.com/2/files/save_url endpoint

Issue with cURL using https://api.dropboxapi.com/2/files/save_url endpoint

bsha100
New member | Level 2

I'm building a small app for a client to backup critical files dropbox. This is happening simultaneously as certain are uploaded to the client's website. Specifically, the files are .jpg, and .png files.

 

The issue that I'm having is that the files are 'uploading', but the uploaded files are only about 860 bytes on DropBox. I've been banging my head against the wall for over 8 hours, and can't find anything but the most scant documentation about this functionality. Below is the code I'm using. The file path and file names come from the file upload, and I have verfied that the image is fully uploaded / moved before proceeding with uploading the file to DropBox.

 

<?php
$path = getcwd();
$file_location = $path.'/images/'.$filename;
		
clearstatcache(); // Clear file stats to ensure accurate info
$filesize = filesize($file_location); 

// Conditional to make sure the complete file is there
if($filesize >= $_FILES["fichier"]["size"]){

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/files/save_url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"path\": \"/images//".$filename."\",\"url\": \"http://www.ClientsWebsiteUrl.com/images/".$filename."\"}");
curl_setopt($ch, CURLOPT_POST, 1);


$headers = array();
$headers[] = "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$headers[] = "Content-Type: application/json";
//
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error '.curl_error($ch);
}else{
	echo 'File Uploaded to DropBox';
}
curl_close ($ch);
}
?>

 

 

I'm hoping for any help I can get here, as I am out of ideas. Thanks everyone!

 

1 Reply 1

Greg-DB
Dropbox Staff

I just tried the API call code you shared here, and it successfully saved a full 52KB .png file to my account. The code seems fine, except for the double '/' in the path parameter, though that shouldn't matter.

 

What data is in the 860 byte file that gets saved for you? Try downloading and opening it. E.g., it might contain a response from your client's website different than what you expected. In that case you'd need to investigate why the client's website isn't returning what you expect.

 

If that's not the issue, please share a sample URL that reproduces the issue so we can look into it. (Feel free to reply on your ticket instead if you want to share it privately.)

 

(By the way, you can use /2/files/upload to upload the file data directly if you'd prefer, instead of providing a URL. There's a sample of using that in PHP via curl here.)

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?