cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

File uploading and downloading in business account.

File uploading and downloading in business account.

nishantcyno
Explorer | Level 4

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.

13 Replies 13

Greg-DB
Dropbox Staff
I'll be happy to help this, but I'll need some more information. Please reply with:

- the name and version of the platform and SDK/library you are using
- the steps to reproduce the issue
- the full text of any error or output
- the relevant code snippet(s)

nishantcyno
Explorer | Level 4

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.

 imgpsh_fullsize.png

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.

Screenshot 2017-01-24 15.07.50.png

- I am doing this by PHP script following snippet shows the my particular logic

Capture1.PNG

Greg-DB
Dropbox Staff
Apologies for the delay! I wasn't notified of your reply for some reason. Are you still having this issue?

If so, can you share your first two screenshots as links? They didn't come through in the post.

nishantcyno
Explorer | Level 4

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.

dropbox nishant.PNG

 

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.

 

dropbox Capture.PNG

 

Pls tell me why this is happening with Business account and reply as soon as possible.

Thanks

Nishant Sharma

Greg-DB
Dropbox Staff

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.

nishantcyno
Explorer | Level 4

Hi Greg, 

 
The official PHP SDK library I am using, works well with my personal dropbox account as I am performing test work there for my client script. Script is same for both accounts (basic and business). Otherwise same issues would encountered on my test or personal dropbox.
 
My goal is to keep the existing file at destination and when same file will again comes with same name, it should be rename and to be place at destination with existing one. I don't want to delete the existing one as you understand through my previous post.
 
Yes, the code is same for both environment or accounts(basic and business).
 
I have checked on my clients localhost server directory that file downloaded as 0Byte and the same file on dropbox found in some KBs. But at my localhost I got downloaded and uploaded successfully.
 
Ok, I will remove that sleep statements. 
 
Thanks Greg for your quick reply/support.
 I have to finish up these issues till end of this week. If you require to further look into that, you can have my testing and business account credentials. Let me know if you need. 
 
With Regards

Greg-DB
Dropbox Staff

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?

 

nishantcyno
Explorer | Level 4

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.

directory count.PNG

 

With Regards

Nishant Sharma

 

Greg-DB
Dropbox Staff

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".

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    nishantcyno Explorer | Level 4
What do Dropbox user levels mean?