Skip to content

Instantly share code, notes, and snippets.

@sharifulin
Created February 2, 2010 17:22
Show Gist options
  • Save sharifulin/292838 to your computer and use it in GitHub Desktop.
Save sharifulin/292838 to your computer and use it in GitHub Desktop.
Mojo uploads
#!/usr/bin/env perl
use lib '../mojo/lib';
BEGIN { $ENV{MOJO_TMPDIR} = 'tmp/upload' };
use Mojolicious::Lite;
use Data::Dumper;
get '/' => 'form';
post '/' => sub {
my $self = shift;
{
open my $fh, '>', 'r';
print $fh $self->req;
}
if (my $u = $self->req->upload('file')) {
warn $u->filename;
$self->stash($u->name => $u->filename);
}
if (my $u = $self->req->upload('image')) {
warn $u->filename;
$self->stash($u->name => $u->filename);
}
} => 'form';
shagadelic(split /\s/, 'daemon --reload --listen http://*:6006 --pid tmp/test.pid --lock tmp/test.lock');
__DATA__
@@ form.html.ep
% layout 'main';
<form method="post" enctype="multipart/form-data">
<input name="image" type="file" />
<input name="file" type="file" />
<input type="submit" />
</form>
<pre>
%= dumper($self->{stash});
</pre>
@@ layouts/main.html.ep
<h1>Test</h1>
<%== content %>
<p>Test!</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment