DropBox: HTTP Error 401 Unauthorized response


When testing download file from DropBox:
 Storage->Download( remotefile, localfile);

Most of time, it works Ok, but sometimes the file received only contains : {"error": "Unauthorized"}

Should the storage component capture this error?


Is this immediately when the download starts or after the download is busy?

Is this when you restart the app with an access token that was loaded or when a new authentication/authorization has happened?
When you use a persisted token, can you try to always call first RefreshToken before starting the download?

Thanks for the reply, here is the detail:

1. Application starts, and then do the followings:  (No problems here )
AdvDropBox1->App->Key =iDropBoxAppkey;
Storage =AdvDropBox1;
if ( Storage->App->Key !="") {
acc = Storage->TestTokens();
if ( !acc) {
acc = Storage->RefreshAccess();
if ( !acc) {

Screen->Cursor = crHourGlass;
Screen->Cursor = crDefault;
}else {
ShowMessage("Please provide a valid application ID");
2. When Time out, get file list from dropbox using 
AdvDropBox1->GetFolderInfo(folder,  AdvDropBox1->DDrive );
TDropBoxItems *myitems = AdvDropBox1->Search(folder,".jpg") ;
3. For each file do:
Storage->Download(remotefile, localfile );
4. Sleep some times and go to step 2

     Most of time, files will be downloaded successfully except: 
    Let's take yesterday as example around 20000 small files ( file size between 5~15K ) have been downloaded.
   1) "Can not open URL... " exception happened twice. I don't know which party: dropbox or your component caused this error.
   2)"Invalid typecast"  exception happened 8 times.  Don't know how this happened yet.
   3) 98 files contain  {"error": "Unauthorized"}
  ( There is another application creates and uploads files to drops continuously.)

   For the moment, my workaround is: check the file size once download finished, if the file size is less 100 bytes, try to download the file again. 
   If it will be good if  "Storage->Download( remotefile, localfile);" could report this error.

Thanks for your help.


Can you do a storage->RefreshAccess() before starting a new download to see if this helps?

Thanks Bruno,

I have tried to use storage->RefreshAccess() but it always return false and furthermore for the 3 test files to be downloaded, the 3rd download always return "Can not Open URL".

And if I remove storage->RefreshAccess(), all the three files can be downloaded without any problem.

Further information:

 "Can not open URL... "  could happen for search,download and delete operations.

Can this be reproduced with our demo app or do you have some sample source project with which we can reproduce this as so far, we haven't seen this problem.

Hi Bruno,

I've tried many times but failed to send the mails with attachments.
error msg:

Delivery to the following recipient failed permanently:


 Technical details of permanent failure:

Google tried to deliver your message, but it was rejected by the server for the recipient domain tmssoftware.com by pop.tmssoftware.com. [].

 The error that the other server returned was:

503 you must authenticate first (#5.5.1)


Hi Bruno,

You can find the attachments here:

You can see from the log that we need to wait about 3 hours to have this errors.