This question follows on from one of my previous ones. The modified large file upload script I am now using is shown below
function uploadFile($local,$remote,$token)
{
$args = 'Dropbox-API-Arg:'.
json_encode(array("path"=>$remote,"mode"=>"overwrite","mute"=>true));
$headers = array("Authorization: Bearer {$token}",
'Content-Type: application/octet-stream',
$args);
$ch = curl_init('https://content.dropboxapi.com/2/files/upload/');
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_PUT,1);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST');
$fp = fopen($local,'rb');
curl_setopt($ch,CURLOPT_INFILE,$fp);
curl_setopt($ch,CURLOPT_INFILESIZE,filesize($local));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$response = curl_exec($ch);
curl_close($ch);
fclose($fp);
//@unlink($local);
echo $response;
}
I have run into two issues here.
- From what I can see the
"mute"=>true
parameter is at times ignored by Dropbox and I end up getting a desktop file update notification anyway. - More of an issue - look at the commented out
@unlink
line. I had this in because I need to discard the$local
file once the Dropbox upload has succeeded. The problem is that if I dounlink
the local file everything works but the uploaded file on Dropbox is empty.
It is not clear to me why this is happening. I have been unable to find any definitive information but my understanding was that cURL calls are always synchronous. If they are not then it is difficult to trust the response from the Dropbox API as being a definitive confirmation that the file has truly been uploaded to Dropbox.
I have come across vague comments about cURL can sometimes be asynchronous in my searches. If that is the case how can I force it to be synchronous? I can always deal with the local file unlink separately via a CRON job that checks its age but that is a messier solution.