Skip to content

Instantly share code, notes, and snippets.

@augensalat
Created September 11, 2012 14:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save augensalat/3699443 to your computer and use it in GitHub Desktop.
Save augensalat/3699443 to your computer and use it in GitHub Desktop.
Simple Mojolicious::Lite upload
#!/usr/bin/env perl
use Mojolicious::Lite;
any '/upload' => sub {
my $self = shift;
# Check file size
return $self->render(text => 'File is too big.', status => 200)
if $self->req->is_limit_exceeded;
# Process uploaded file
if (my $example = $self->req->upload('example')) {
my $size = $example->size;
my $name = $example->filename;
$self->render(text => "Thanks for uploading $size byte file $name.");
}
};
app->start;
__DATA__
@@ upload.html.ep
<!DOCTYPE html>
<html>
<head><title>Upload</title></head>
<body>
% my @attrs = (method => 'POST', enctype => 'multipart/form-data');
%= form_for upload => @attrs => begin
%= file_field 'example'
%= submit_button 'Upload'
% end
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment