Skip to content

Instantly share code, notes, and snippets.

@Logioniz
Created April 24, 2015 11:26
Show Gist options
  • Save Logioniz/18e405746da25351f379 to your computer and use it in GitHub Desktop.
Save Logioniz/18e405746da25351f379 to your computer and use it in GitHub Desktop.
Upload big file to server. Server save it to temp directory.
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
use Mojo::UserAgent;
say Mojo::UserAgent->new->post('http://127.0.0.1:3000/' => form => {
pdf => {
content => '1' x (256 * 1024 + 1),
filename => 'very_big_file.pdf'
}
})->res->body;
#!/usr/bin/perl
# if file small then is_file = undef else is_file = 1
use strict;
use warnings;
use Mojolicious::Lite;
post '/' => sub {
my $c = shift;
my $upload = $c->req->upload('pdf');
_print(size => $upload->size);
_print(filename => $upload->filename);
my $asset = $upload->asset;
_print(is_file => $asset->is_file ? 'true' : 'false');
if ($asset->is_file) {
_print(tmpdir => $asset->tmpdir);
_print(path => $asset->path);
#_print(content => $asset->slurp);
}
$c->render(text => 'Ok');
};
sub _print {
my ($key, $value) = @_;
app->log->info(sprintf("%10s: %s", $key, $value));
}
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment