Created
September 11, 2012 14:59
-
-
Save augensalat/3699443 to your computer and use it in GitHub Desktop.
Simple Mojolicious::Lite upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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