mojolicious Streaming receive large files?

72 views
Skip to first unread message

扶凯

unread,
Jul 4, 2014, 6:21:16 AM7/4/14
to mojol...@googlegroups.com
I want to send large files via post, but this time did not 'multipart / form-data' head.
like this

use Mojo::UserAgent;
use Mojo::Asset::File;

my $ua = Mojo::UserAgent->new;
$ua->transactor->add_generator(stream => sub {
  my ($transactor, $tx, $path) = @_;
  $tx->req->content->asset(Mojo::Asset::File->new(path => $path));
});

$ua->post('http://f.xxx.com:3000/upload' => stream => '/root/index.html');


I do not want to generate a temporary file. It is not appropriate to use upload method to handle. I wrote this hook below.


hook after_build_tx => sub {
  my $tx = shift;

  weaken $tx;
  $tx->req->content->on(  body => sub {
        my $content = shift;
        $content->unsubscribe('read');
        $content->on(read => sub {
            my ($content, $bytes) = @_;
            say "Streaming: $bytes";
        });
  });
};


This does not work properly, or will generate Mojo :: Asset :: File object. I hope it nonblocking write files, so more than one person the right to upload large files.I want to ask how to write in order to stream the hook receiving large files?
Reply all
Reply to author
Forward
0 new messages