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"