We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
sunshine_sai
5 years agoHelpful | Level 5
Re: My uploaded files on Dropbox are 0 bytes/ empty.
I am uploading files using API v2 in php and getting the same issue with some selected files or file type, can you help me?
5 Replies
- Greg-DB5 years ago
Dropbox Community Moderator
I'll be happy to help with any issues you're having with the Dropbox API, but I'll need some more information. Please reply with:
- the name and version number of the platform and SDK/library you are using, if any
- the steps to reproduce the issue, including relevant code snippet(s), but don't include any access token(s)
- the full text of any error or unexpected output
- sunshine_sai5 years agoHelpful | Level 5
$fileURL = 'http://localhost/wordpress/wp-content/uploads/2021/05/my-file.txt';
$tempFilePath = basename($fileURL);
try{
$path = $tempFilePath;
$fp = fopen($path, 'rb');
$size = filesize($path);
$cheaders = array('Authorization: Bearer <ACCESS_TOKEN>',
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: {"path":"/'.$path.'", "mode":"add"}');$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($ch);
curl_close($ch);
fclose($fp);
$jsonData= $resp; // put here your json object
$arrayData = json_decode($jsonData, true);
if($arrayData['size'] != 0 ){
print_r($arrayData);
// Removed file from this server atfer moved in dropbox Storage.
wp_delete_attachment($dt['upload_file_id'] );$response = array('status' => 'success');
$response['success'] = true;
}I am getting this output:-
array printed:
Array
(
[name] => my-file.txt
[path_lower] => /my-file.txt
[path_display] => /my-file.txt
[id] => id:B5l9vJBpsTAAAAAAAAAAbQ
[client_modified] => 2021-05-28T11:30:07Z
[server_modified] => 2021-05-28T11:30:07Z
[rev] => 015c36232ad2ec4000000019de99780
[size] => 0
[is_downloadable] => 1
[content_hash] => 1dc1597f40484ade184602a580c89f61adcedf3c5be81c74e31748ba36f2d5b9
)Response which I am getting :
{"status":"success","success":true,"dtarray":"{\"name\": \"s12-compressor.jpg\", \"path_lower\": \"\/s12-compressor.jpg\", \"path_display\": \"\/s12-compressor.jpg\", \"id\": \"id:B5l9vJBpsTAAAAAAAAAAbQ\", \"client_modified\": \"2021-05-28T11:30:07Z\", \"server_modified\": \"2021-05-28T11:30:07Z\", \"rev\": \"015c36232ad2ec4000000019de99780\", \"size\": 0, \"is_downloadable\": true, \"content_hash\": \"1dc1597f40484ade184602a580c89f61adcedf3c5be81c74e31748ba36f2d5b9\"}"}
- Greg-DB5 years ago
Dropbox Community Moderator
I just gave this a try myself, plugging in my own access token and local file path, and it successfully uploaded a non-empty file as expected for me.
You should check that your local file is non-empty and is being accessed successfully. For instance, check what the value of "$size" is for you, and make sure your "$fileURL", "$tempFilePath", and "$path" values are correct.
- sunshine_sai4 years agoHelpful | Level 5
Thanks Sometimes this code not working and a blank file with 0kb is uploaded on dropbox sever.
- Greg-DB4 years ago
Dropbox Community Moderator
Have you checked the suggestions in my last message?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 2 days ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!