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: 

http header issue with file send via php curl

http header issue with file send via php curl

FSUInnovation
Explorer | Level 4
Go to solution

I keep getting errors in my php code regarding a missing authorization header in my http request using curl. This is what my code looks like:

$doc = $_FILES['Resume'];
$filename = $doc['tmp_name'];
$dropbox_token = "token";
$dropbox_url = "https://content.dropboxapi.com/2/files/upload";
/*$dropbox_api_headers = array('Authorization: Bearer '. $dropbox_token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.
json_encode(
array(
"path"=> '/'. basename($filename),
"mode" => "add",
"autorename" => true,
"mute" => false
)
)

);*/
$opendoc = fopen($filename, 'rb');
$docsize = $_FILES['Resume']['size'];
$d1curl = curl_init();
$timeout = 50;
curl_setopt($d1curl, CURLOPT_URL, $dropbox_url);
curl_setopt($d1curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($d1curl, CURLOPT_HEADER, [
utf8_encode('Authorization: Bearer ' . $dropbox_token),
utf8_encode('Content-Type: application/octet-stream'),
utf8_encode('Dropbox-API-Arg: '.
json_encode(
array(
"path"=> '/'. basename($filename),
"mode" => "add",
"autorename" => true,
"mute" => false
)))]);
curl_setopt($d1curl, CURLOPT_POST, true);
curl_setopt($d1curl, CURLOPT_POSTFIELDS, fread($opendoc, $docsize));
curl_setopt($d1curl, CURLOPT_RETURNTRANSFER, true);
$dropbox_upload = curl_exec($d1curl);
$http_request = curl_getinfo($d1curl, CURLINFO_HTTP_CODE);
echo $dropbox_upload;
echo $http_request;
curl_close($d1curl);
fclose($opendoc);

I wonder why dropbox is giving me for errors as I followed similiar instructions seen on stackoverflow for file send and also referenced the api explorer.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

According to the PHP curl documentation, the 'CURLOPT_HEADER' option is to "to include the header in the output". It doesn't set the headers for the request. You should use the 'CURLOPT_HTTPHEADER' option for that instead.

View solution in original post

1 Reply 1

Greg-DB
Dropbox Staff
Go to solution

According to the PHP curl documentation, the 'CURLOPT_HEADER' option is to "to include the header in the output". It doesn't set the headers for the request. You should use the 'CURLOPT_HTTPHEADER' option for that instead.

Need more support?
Who's talking

Top contributors to this post

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