package MyApp::Web::Dispatcher; use strict; use warnings; use utf8; use Amon2::Web::Dispatcher::Lite; any '/' => sub { my ($c) = @_; return $c->render('index.tt'); }; post '/account/logout' => sub { my ($c) = @_; $c->session->expire(); return $c->redirect('/'); }; 1;
package MyApp::Web::Dispatcher; use strict; use warnings; use utf8; use Amon2::Web::Dispatcher::Lite; any '/' => sub { my ($c) = @_; return $c->render('index.tt'); }; post '/account/logout' => sub { my ($c) = @_; $c->session->expire(); return $c->redirect('/'); }; 1; SFTQPOTFΛฦ͢
CREATE TABLE IF NOT EXISTS image ( id INTEGER NOT NULL PRIMARY KEY, filename VARCHAR(64), src TEXT, ctime INT UNSIGNED NOT NULL, UNIQUE (filename) ); TRMTRMJUFTRM
use DBD::Pg; use Digest::MD5 qw/md5_hex/; post '/upload' => sub { my ($c) = @_; my $imagedata = $c->req->upload('imagedata') or die; # アップロードできる画像は1MB未満とする die unless $imagedata->size < 1024 * 1024; # 画像データを読み込む my $src = do { open my $fh, '<:raw', $imagedata->path or die $!; local $/; <$fh>; }; # PNGであることをシグネチャで判定する die unless $src =~ /^\x89PNG\x0d\x0a\x1a\x0a/; my $filename = md5_hex($src) . '.png'; $c->db->fast_insert('image', { filename => $filename, src => [$src, {pg_type => DBD::Pg::PG_BYTEA}], ctime => time(), }); my $url = $c->req->base . $filename; return $c->create_response(200, [], [$url]); };
use DBD::Pg; use Digest::MD5 qw/md5_hex/; post '/upload' => sub { my ($c) = @_; my $imagedata = $c->req->upload('imagedata') or die; # アップロードできる画像は1MB未満とする die unless $imagedata->size < 1024 * 1024; # 画像データを読み込む my $src = do { open my $fh, '<:raw', $imagedata->path or die $!; local $/; <$fh>; }; # PNGであることをシグネチャで判定する die unless $src =~ /^\x89PNG\x0d\x0a\x1a\x0a/; my $filename = md5_hex($src) . '.png'; $c->db->fast_insert('image', { filename => $filename, src => [$src, {pg_type => DBD::Pg::PG_BYTEA}], ctime => time(), });
use DBD::Pg; use Digest::MD5 qw/md5_hex/; post '/upload' => sub { my ($c) = @_; my $imagedata = $c->req->upload('imagedata') or die; # アップロードできる画像は1MB未満とする die unless $imagedata->size < 1024 * 1024; # 画像データを読み込む my $src = do { open my $fh, '<:raw', $imagedata->path or die $!; local $/; <$fh>; }; # PNGであることをシグネチャで判定する die unless $src =~ /^\x89PNG\x0d\x0a\x1a\x0a/; my $filename = md5_hex($src) . '.png'; $c->db->fast_insert('image', { filename => $filename, src => [$src, {pg_type => DBD::Pg::PG_BYTEA}], ctime => time(), }); perldoc Plack::Request::Upload
$ heroku addons:add heroku-postgresql Adding heroku-postgresql on sheltered-earth-3211... done, v6 (free) Attached as HEROKU_POSTGRESQL_CYAN_URL Database has been created and is available ! This database is empty. If upgrading, you can transfer ! data from another database with pgbackups:restore. Use `heroku addons:docs heroku-postgresql` to view documentation. $ heroku pg:psql HEROKU_POSTGRESQL_CYAN_URL < sql/pg.sql NOTICE: CREATE TABLE will create implicit sequence "image_image_id_seq" for serial column "image.image_id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "image_pkey" for table "image" NOTICE: CREATE TABLE / UNIQUE will create implicit index "image_filename_key" for table "image" CREATE TABLE
$ heroku addons:add heroku-postgresql Adding heroku-postgresql on sheltered-earth-3211... done, v6 (free) Attached as HEROKU_POSTGRESQL_CYAN_URL Database has been created and is available ! This database is empty. If upgrading, you can transfer ! data from another database with pgbackups:restore. Use `heroku addons:docs heroku-postgresql` to view documentation. $ heroku pg:psql HEROKU_POSTGRESQL_CYAN_URL < sql/pg.sql NOTICE: CREATE TABLE will create implicit sequence "image_image_id_seq" for serial column "image.image_id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "image_pkey" for table "image" NOTICE: CREATE TABLE / UNIQUE will create implicit index "image_filename_key" for table "image" CREATE TABLE
$ heroku addons:add heroku-postgresql Adding heroku-postgresql on sheltered-earth-3211... done, v6 (free) Attached as HEROKU_POSTGRESQL_CYAN_URL Database has been created and is available ! This database is empty. If upgrading, you can transfer ! data from another database with pgbackups:restore. Use `heroku addons:docs heroku-postgresql` to view documentation. $ heroku pg:psql HEROKU_POSTGRESQL_CYAN_URL < sql/pg.sql NOTICE: CREATE TABLE will create implicit sequence "image_image_id_seq" for serial column "image.image_id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "image_pkey" for table "image" NOTICE: CREATE TABLE / UNIQUE will create implicit index "image_filename_key" for table "image" CREATE TABLE
$ heroku addons:add heroku-postgresql Adding heroku-postgresql on sheltered-earth-3211... done, v6 (free) Attached as HEROKU_POSTGRESQL_CYAN_URL Database has been created and is available ! This database is empty. If upgrading, you can transfer ! data from another database with pgbackups:restore. Use `heroku addons:docs heroku-postgresql` to view documentation. $ heroku pg:psql HEROKU_POSTGRESQL_CYAN_URL < sql/pg.sql NOTICE: CREATE TABLE will create implicit sequence "image_image_id_seq" for serial column "image.image_id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "image_pkey" for table "image" NOTICE: CREATE TABLE / UNIQUE will create implicit index "image_filename_key" for table "image" CREATE TABLE
$ heroku addons:add heroku-postgresql Adding heroku-postgresql on sheltered-earth-3211... done, v6 (free) Attached as HEROKU_POSTGRESQL_CYAN_URL Database has been created and is available ! This database is empty. If upgrading, you can transfer ! data from another database with pgbackups:restore. Use `heroku addons:docs heroku-postgresql` to view documentation. $ heroku pg:psql HEROKU_POSTGRESQL_CYAN_URL < sql/pg.sql NOTICE: CREATE TABLE will create implicit sequence "image_image_id_seq" for serial column "image.image_id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "image_pkey" for table "image" NOTICE: CREATE TABLE / UNIQUE will create implicit index "image_filename_key" for table "image" CREATE TABLE