Skip to content

Instantly share code, notes, and snippets.

@akiym
Created August 15, 2010 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akiym/525295 to your computer and use it in GitHub Desktop.
Save akiym/525295 to your computer and use it in GitHub Desktop.
Gyazo
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::Asset::File;
use Digest::MD5 qw(md5_hex);
use File::Spec;
use IO::File;
my $dir = app->home->rel_dir('images');
unless (-d $dir) {
warn "Creating $dir\n";
mkdir $dir;
}
post '/upload' => sub {
my $self = shift;
my $imagedata = $self->param('imagedata');
my $filename = md5_hex($imagedata) . '.png';
my $path = File::Spec->catfile($dir, $filename);
my $file = Mojo::Asset::File->new(
path => $path,
handle => IO::File->new($path, 'w'),
);
$file->add_chunk($imagedata);
$self->render(text => $self->req->url->base . '/' . $filename);
};
app->static(
MojoX::Dispatcher::Static->new(
root => $dir,
)
);
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment