HTTP::Request::StreamingUpload - streaming upload wrapper for HTTP::Request
my $req = HTTP::Request::StreamingUpload->new( PUT => 'http://example.com/foo.cgi', path => '/your/upload.jpg', headers => HTTP::Headers->new( 'Content-Type' => 'image/jpeg', 'Content-Length' => -s '/your/upload.jpg', ), ); my $res = LWP::UserAgent->new->request($req);
open my $fh, '<', '/your/upload/requestbody' or die $!; my $req = HTTP::Request::StreamingUpload->new( PUT => 'http://example.com/foo.cgi', fh => $fh, headers => HTTP::Headers->new( 'Content-Length' => -s $fh, ), ); my $res = LWP::UserAgent->new->request($req);
my @chunk = qw( foo bar baz ); my $req = HTTP::Request::StreamingUpload->new( PUT => 'http://example.com/foo.cgi', callback => sub { shift @chunk }, headers => HTTP::Headers->new( 'Content-Type' => 'text/plain', 'Content-Length' => 9, ), ); my $res = LWP::UserAgent->new->request($req);
HTTP::Request::StreamingUpload is streaming upload wrapper for HTTP::Request. It could be alike when $DYNAMIC_FILE_UPLOAD of HTTP::Request::Common was used. However, it is works only for POST method with form-data. HTTP::Request::StreamingUpload works on the all HTTP methods.
Of course, you can big file upload using few memory by this wrapper.
header is passed. HASHREF, ARRAYREF or HTTP::Headers object can be passed.
If you are possible, you should set up Content-Length for file upload. However, chunked upload for HTTP 1.1 will be performed by LWP::UserAgent if it does not set up.
Content-Length
set the upload file path.
set the file-handle of upload file. It can use instead of path.
path
set the buffer size when reading the file of fh or path.
fh
Instead of path or fh, upload data is controlled by itself and can be made.
# 10 times send epoch time callback => sub { return if $i++ > 10; return time() . "\n"; },
Kazuhiro Osawa <yappo <at> shibuya <döt> pl>
HTTP::Request, HTTP::Request::Common, HTTP::Headers, LWP::UserAgent
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in '<döt>'. Assuming UTF-8
To install HTTP::Request::StreamingUpload, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Request::StreamingUpload
CPAN shell
perl -MCPAN -e shell install HTTP::Request::StreamingUpload
For more information on module installation, please visit the detailed CPAN module installation guide.