Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi Dropboxer,
I am working on dropbox api in PHP and managing file and folder through running a script from server. All things are working file only issue which I am facing is to uploading a existing or simply downloading a file.
I have successfully placed a API call and file is downloading inside my root directory but it is showing only 0Byte and same for placing uploading, I have received this 0Byte file on my dropbox.
Why this is happening. I have tested script on Basic version of my dropbox working fine. But on Business account (my client's) I couldn't able to do this.
Pls tell me know is there any problem with Buisness account.
Thanks,
Following the tutorials from https://www.dropbox.com/developers-v1/core/sdks/php
-I'm using Composer for your project's dependencies, I have just add dropbox-sdk to your composer.json instead of downloading the SDK.
dropbox/dropbox-sdk": "1.1.*"
-I have successfully moved files from one folder to another folder through move($sourcepath,$destpath) API function. But I have a particular case where file may already exits at destination. So I have take a file from my dropbox $sourcepath and download in my system and then upload it on destination path. By doing this existing file remain there and new file got renamed and saved to dropbox $destpath. But showing 0Byte along with file name. Below screenshot shows a simillar issue inside my client's dropbox account. File size shows 0Byte.
I have tried same with my basic Dropbox account and I am able to do it successfully. Below is the output Which I want for my client's Dropbox account.
- I am doing this by PHP script following snippet shows the my particular logic
Thanks Greg
I still have this issue, as I told you that my code(the earlier third screenshot) is working fine for this particular case where file is already in the destination location, it got renamed by placing '(1)' at end and showing 430.56KB) in my basic dropbox account. Below is my account's screenshot.
Now, the above thing is not working on my client's business dropbox account. The file got renamed but showing 0Byte meaning something is not working on business account. Below is the screenshot.
Pls tell me why this is happening with Business account and reply as soon as possible.
Thanks
Nishant Sharma
Thanks for the additional information! I took a look over your post and code.
First, I should note that you're using the PHP SDK for API v1, which is deprecated. You should migrate to API v2 as soon as possible. We don't have an official PHP SDK for API v2, but you can use a third party library, or call the HTTPS endpoints directly.
Anyway, it sounds like the original goal was to replace a file that already exists. You're downloading and re-uploading the file to do so, but a more efficient alternative would be to just delete the existing file at the destination. That would save you the time and bandwidth for the download and upload. (We'll consider this a request for write mode options for moving files anyway though.) In the code you have though, you're using WriteMode::add, which won't overwrite the destination file. It sounds like you want WriteMode::force instead.
In any case, the type of account (e.g., basic versus business) shouldn't make any difference in the upload functionality like this. Are you definitely running the same code in both cases?
Further, in order to track down where the 0 byte file is coming from, please check the size of the local file. That way, we can determine if the upload itself is not working properly for you, or if it's the download.
If the local file is 0 bytes, please then check if the original source file on Dropbox is 0 bytes. That would indicate if there's an issue with the download call itself, or if this is working properly and the file does just happen to be 0 bytes.
Finally, I see that you have some sleep statements in your code after the download and upload calls. Those calls block, so you don't need to add any sleep. The code won't proceed until the operation is done.
Hi Greg,
Since the downloaded file itself is 0 bytes, and the remote file isn't, it appears the issue is with the download operation itself.
To continue debugging this, we should isolate the download call. For example, I just tried this based on your code, and it worked fine for me:
print_r("filename is: $filename \n");
print_r("source is: $source \n");
$ffd = fopen("./files/$filename", "wb");
$metadata = $client->getFile($source, $ffd);
print_r("Received metadata: ");
print_r($metadata);
fclose($ffd);
It successfully downloaded a non-zero-byte file from a business account.
Can you try that in your client's environment and share any error or output you get?
Hi Greg,
Thanks for your continuous support. You have solved my downloading and uploading issue.
I have one more query regarding dropbox API.
How do I count the no. of directories inside any directory on my dropbox?
Here is my code which is not working right now.
With Regards
Nishant Sharma
This screenshot also didn't work unfortunately, but if you're still using the API v1 PHP SDK, you can use getDelta (preferably) or getMetadataWithChildren to get the contents of the directory in question, and then count the number of entries where is_dir is true.
For API v2, you would use /files/list_folder[/continue] and count the number of returned entries where the ".tag" is "folder".
Hi there!
If you need more help you can view your support options (expected response time for a 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!