我正尝试使用PUT方法通过Mojo :: UserAgent上传文件,该文件可能很大,而不是将文件内容作为标量传递,还有其他方法吗?
这是我尝试过的:
use strict;
use warnings;
use Mojo::UserAgent;
use Mojo::Asset::File;
my $ua = Mojo::UserAgent->new;
my $file = $ARGV[0];
die("File not found") unless(-f $file);
my $a_file = Mojo::Asset::File->new(path => $file);
my $tx = $ua->put('https://postman-echo.com/put' => {'X-Test' => '123G'} => $a_file);
print $tx->success;
print "\n\n";
print $tx->result->body;
print "\n\n";
print $tx->req->text;
答案 0 :(得分:3)
请参见build_tx
in Mojo::UserAgent,并注释示例
# PUT request with content streamed from file
在tx
in Mojo::UserAgent::Transactor。
my $ua = Mojo::UserAgent->new;
my $put = $ua->build_tx(PUT => '…' => {'X-Test' => '123G'});
$put->req->content->asset(Mojo::Asset::File->new(path => $file));
my $tx = $ua->start($put);