frank1 has asked for the wisdom of the Perl Monks concerning the following question:

i have a problem of uploading files to Dropbox, this is the error i get

[WebService::Dropbox] [ERROR] https://content.dropboxapi.com/2/files/u +pload {"path":"/Uploads/$filename"} -> [400] Error in call to API fun +ction "files/upload": Must provide HTTP header "Authorization" or URL + parameter "authorization". at WebService/Dropbox.pm line 184.

My full code

#!/usr/bin/perl use lib '.'; use strict; use warnings; use WebService::Dropbox; use IO::File; my $filename = '/var/www/vhosts/path/httpdocs/path/file.txt'; my $access_token = ''; my $dropbox = WebService::Dropbox->new({ key => $access_token, # oauth2 is true by default for recent versions }); my $local_file = $filename; my $remote_path = '/Uploads/$filename'; my $content = IO::File->new($local_file, '<') or die "Cannot open $loc +al_file: $!"; my $result = $dropbox->upload($remote_path, $content); if ($result) { print "Successfully uploaded $local_file to Dropbox as $remote_pat +h\n"; } else { die "Upload failed: " . $dropbox->error; }

Replies are listed 'Best First'.
Re: Dropbox problem
by talexb (Chancellor) on Dec 24, 2025 at 15:18 UTC
      [400] Error in call to API function "files/upload": Must provide HTTP header "Authorization" or URL parameter "authorization"

    It looks like Dropbox is telling you what the problem is.

    Alex / talexb / Toronto

    As of June 2025, Groklaw is back! This site was a really valuable resource in the now ancient fight between SCO and Linux. As it turned out, SCO was all hat and no cattle.Thanks to PJ for all her work, we owe her so much. RIP -- 2003 to 2013.

      How to fix it

Re: Dropbox problem
by pryrt (Abbot) on Dec 24, 2025 at 16:39 UTC
    In looking at the SYNOPSIS for WebService::Dropbox , your code doesn't seem to follow their example pattern.

    I assume you deleted the value of $access_token from your post for security reasons (reasonable). But assuming there is a token value there, you seem to be passing the token into the key for the $dropbox object. But the SYNOPSIS shows you need to pass in a key and a secret , and then you should do $dropbox->access_token($access_token); if you have a token already. You aren't following that pattern. Do you have a reason for not following that pattern? (Maybe there's some other example I haven't found in the docs that show passing the token into the key attribute, but I cannot find such on the main page of the documentation).

    thus, my guess as to what you really want:

    #!/usr/bin/perl use lib '.'; use strict; use warnings; use WebService::Dropbox; use IO::File; my $filename = '/var/www/vhosts/path/httpdocs/path/file.txt'; my $access_token = ''; # TOKEN goes here my $key = ''; # APPLICATION KEY goes here my $secret = ''; # APPLICATION SECRET goes here my $dropbox = WebService::Dropbox->new({ key => $key, # this should be KEY, not TOKEN secret => $secret, # this should be SECRET, not skipped # oauth2 is true by default for recent versions }); $dropbox->access_token($access_token); # must send dropbox the access +token AFTER the key/secret was defined when object was instantiated my $local_file = $filename; my $remote_path = '/Uploads/$filename'; my $content = IO::File->new($local_file, '<') or die "Cannot open $loc +al_file: $!"; my $result = $dropbox->upload($remote_path, $content); if ($result) { print "Successfully uploaded $local_file to Dropbox as $remote_pat +h\n"; } else { die "Upload failed: " . $dropbox->error; }

    Untested, since I don't have dropbox developer credentials. But this would be the next thing I tried, if I were you.


    update: looking at the new method source code (since they don't document the arguments), you might be able to pass in WebService::Dropbox->new({access_token => $access_token}); as part of the instantiation. I don't know whether the key and secret are required if you include the token or not (the module doesn't have sufficient documentation for the constructor, IMO), so you might try with both -- but really, following the SYNOPSIS (as I suggested above) is a better place to start than trying to reverse-engineer the other parameters for the constructor.

      thank you so much for help, your code is working