This question follows on from my previous question on the same subject. Simple file uploads are, well, simple.
$headers = array("Authorization: Bearer dropbox_token",
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: {"path":"/path/file.ext",
"mode":"add"}');
$data = "I love Stackoverflow";
$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,$data);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
However, this is not a viable option when the file data to be save run into 10s of megabytes. I thought I would simply use the new(ish) PHP curl_file_create.
$headers = array("Authorization: Bearer Dropbox token",
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: {"path":"/path/bigfile.txt",
"mode":"add"}');
$ch = curl_init('https://content.dropboxapi.com/2/files/upload/');
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
$args['file'] = curl_file_create('/path/to/bigfile.txt');
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$args);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
However, this does not work. The Dropbox API returns the message
Error in call to API function "files/upload": Bad HTTP "Content-Type" header: "application/octet-stream; boundary=--... Expecting one of "application/octet-stream", "text/plain; charset=dropbox-cors-hack
I would be most grateful to anyone who could tell me where I might be going wrong here.