This question follows on from my previous question on the same subject. Simple file uploads are, well, simple.
$headers = array(\"Authorization: Be
If anyone interested a quick fix on Dropbox API v2 which CURLOPT_INFILE
is not working, go to this link Dropbox PHP v2 upload issue
Greg explain and suggested to used this code curl_setopt($ch, CURLOPT_POSTFIELDS, fread($fp, $filesize))
instead of curl_setopt($ch, CURLOPT_INFILE, $fp);
It looks like curl_file_create
encodes a file as a multipart form upload, which isn't what you want when talking to the Dropbox API.
If I understand correctly, the issue you're trying to address is that you don't want to load the entire file contents into memory. Is that right?
If so, please give the following a try. (Apologies that I haven't tested it at all, so it may contain mistakes.)
$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);
curl_setopt($ch, CURLOPT_POST, true);
$path = '/path/to/bigfile.txt';
$fp = fopen($path, 'rb');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
fclose($fp);
echo $response;
Note that you may also want to consider /files/upload_session_start, etc. if you're uploading large files. That lets you upload in chunks, and it supports files bigger than 150MB (which /files/upload
does not).