Created
January 23, 2013 19:55
-
-
Save mala/4612270 to your computer and use it in GitHub Desktop.
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
use strict; | |
use Plack::Builder; | |
use Plack::Request; | |
use Plack::App::Directory; | |
use Path::Class; | |
use Digest::MD5 qw(md5_hex); | |
my $upload_dir = "./files/"; | |
builder { | |
mount "/files" => Plack::App::Directory->new(root => $upload_dir); | |
mount "/upload" => sub { | |
my $env = shift; | |
my $req = Plack::Request->new($env); | |
if ($req->method eq "POST") { | |
my $file = file($upload_dir . md5_hex($req->param("key"))); | |
my $appender = $file->open('a') or die $!; | |
$appender->print($req->raw_body); | |
$appender->close; | |
# warn $req->raw_body; | |
} | |
[200, [], ["OK"]]; | |
}; | |
mount "/" => sub { | |
my $env = shift; | |
if ($env->{PATH_INFO} eq "/") { | |
return Plack::App::File->new(file => './static/index.html')->call($env); | |
} | |
Plack::App::File->new(root => './static/')->call($env); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment