Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: LWP::Useragent - File Upload

by poj (Abbot)
on Dec 15, 2018 at 14:14 UTC ( [id://1227299]=note: print w/replies, xml ) Need Help??


in reply to LWP::Useragent - File Upload

Try using just Content_Type => 'form-data' or Content_Type => 'multipart/form-data; boundary="xYzZY"'

#!/usr/bin/perl use strict; use warnings; use MIME::Base64; use HTTP::Request::Common; my $file = "/tmp/test_image.tgz.bin"; my $url = "https://10.248.179.31/api/rest/software_package"; my $request = HTTP::Request::Common::POST( $url, Authorization => 'Basic ' . encode_base64('user:password'), Content_Type => 'multipart/form-data; boundary="xYzZY"', Content => [ file => [$file] ], ); print $request->as_string;
poj

Replies are listed 'Best First'.
Re^2: LWP::Useragent - File Upload
by leefp (Initiate) on Dec 20, 2018 at 19:51 UTC
    I'm already using that...See the code posted above. Thanks

      Did you try the code I posted ?

      poj
        As I spent hours to make it finally work, here my working solution:
        my $ua = LWP::UserAgent->new(); my $url = "http://your_url"; my $filename = "d:\\clips\\videoclip.mp4"; my $response = $ua->post($url, ['file' => [ $filename ]], 'Content_Type' => 'form-data' # add here more header paramete +rs if necessary );
        #!/usr/bin/perl -w use LWP::UserAgent; use JSON; use Encode; use utf8; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $url = "xxx"; my $token = 'x'; my $sign = 'xxxxx'; my $file = '/home/xxx/xxxxxxxxxx.jpg'; my $response = $ua->post($url, ["token" => $token, "sign" => $sign, "image" => [$file] ], 'Content_Type' => 'form-data'); if ( $response->is_success ) { print $response->decoded_content,"\n"; } else { die $response->status_line; }

        the file param "image" use an Array "$file"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1227299]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found