Skip to content

Instantly share code, notes, and snippets.

@sharifulin
Created November 1, 2010 15:41
Show Gist options
  • Save sharifulin/658382 to your computer and use it in GitHub Desktop.
Save sharifulin/658382 to your computer and use it in GitHub Desktop.
Uploadify and Mojolicious app
#!/usr/bin/env perl
BEGIN { $ENV{MOJO_MAX_MESSAGE_SIZE} = 50 * 1024 * 1024; }
use Mojolicious::Lite;
my $conf = { path => 'data/uploads/', ext => qr/\.(?i:mp3|wav|wma|ogg)$/ };
post '/uploadify/check' => sub {
my $self = shift;
my $param = $self->req->params->to_hash;
my $exists = {};
for (keys %$param) {
next if /^folder$/; # exclude uploadify param
next unless -f $conf->{path} . $param->{$_};
$exists->{$_} = $param->{$_};
}
$self->render_json( $exists );
};
post '/uploadify/submit' => sub {
my $self = shift;
return unless my $upload = $self->req->upload('Filedata');
return $self->render_text( 'Invalid file type' ) unless $upload->filename =~ /$conf->{ext}/;
$upload->move_to ( $conf->{path} . $upload->filename );
$self->render_text( $upload->filename );
};
app->log->level('error');
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment