cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: 

Upload Image with Dropbox API

Upload Image with Dropbox API

ws
New member | Level 2

Hi,

When Iam uploadinh the image using the curl code.The response is 200 ok,but when iam viewing the image in the dropbox .It says unable to preview this type of images.My code is:

 

 

$fields ='@'.'test.jpg';
$headers = array("Authorization: Bearer ".$token,'Content-Type: application/octet-stream', 'Dropbox-API-Arg: {"path":"/arun/teshhhhht.jpeg","autorename": true,"mute": false,"mode":"add"}');
$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);;
$rest1=json_decode($response,true);
echo "<pre>";
print_r($response);

1 Reply 1

Greg-DB
Dropbox Staff

It looks like you're uploading the file data as the string "@test.jpg" as opposed to the contents of the file at test.jpg. (According to the documentation for CURLOPT_POSTFIELDS that usage for accessing file contents is deprecated, and only works when supplying the full path.)

 

The resulting uploaded file then won't be the expected image data, so the thumbnail call won't work.

 

There's an example of uploading a file using curl in PHP here:

 

https://stackoverflow.com/documentation/dropbox-api/409/uploading-a-file/1354/uploading-a-file-via-c...

Need more support?
Who's talking

Top contributors to this post

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