5 use Template
::Perlish
qw( render );
8 use Net
::Amazon
::S3
::Policy
;
11 print {*STDERR
} <<'DOCUMENTATION';
12 perl sample-form.pl <AWS-ID> <AWS-secret> <bucket>
14 Prints the policy on STDERR, prints the sample web page with the form
20 } ## end if (@ARGV != 3)
22 my ($aws_key, $aws_secret, $bucket) = @ARGV;
23 my $policy = Net
::Amazon
::S3
::Policy
->new(
24 expiration
=> time() + 60 * 60, # one-hour policy
26 'key starts-with restricted/', # restrict to here
27 "success_action_redirect starts-with http://$bucket.s3.amazonaws.com/restricted/",
29 'Content-Type starts-with image/',
30 'x-amz-meta-colour *',
35 print {*STDERR
} $policy->json(), "\n";
37 my $template = do { local $/; <DATA
> };
38 print {*STDOUT
} render
(
40 policy
=> $policy->base64(),
41 signature
=> $policy->signature_base64($aws_secret),
42 AWSAccessKeyId
=> $aws_key,
47 <?xml version
="1.0" encoding
="utf-8"?
>
48 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
49 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
50 <html xmlns
="http://www.w3.org/1999/xhtml" xml
:lang
="en" lang
="en">
53 <title
>An example form page
for Amazon S3 HTTP POST interface
</title
>
54 <meta http
-equiv
="content-type" content
="text/html;charset=utf-8" />
55 <meta http
-equiv
="Content-Style-Type" content
="text/css" />
57 * {margin
:0; padding
:0;}
60 div
.clearer
{ clear
: both
; }
64 border
: 1px solid
#ccc;
81 border
:1px solid
#ddd;
89 <h1
>Amazon S3 HTTP POST
</h1
>
91 <form action
="https://[% bucket %].s3.amazonaws.com/" method
="post"
92 enctype
="multipart/form-data" id
="uploader">
94 <legend
>File Upload
</legend
>
96 <!-- inputs needed because bucket is
not publicly writeable
-->
97 <input type
="hidden" name
="AWSAccessKeyId" value
="[% AWSAccessKeyId %]" />
98 <input type
="hidden" name
="policy" value
="[% policy %]" />
99 <input type
="hidden" name
="signature" value
="[% signature %]" />
101 <!-- input needed by AWS
-S3 logic
: there MUST be a key
-->
102 <input type
="hidden" name
="key" value
="restricted/${filename}" />
104 <!-- inputs that you want to include
in your form
-->
105 <input type
="hidden" name
="acl" value
="public-read" />
106 <input type
="hidden" name
="Content-Type" value
="image/jpeg" />
107 <input type
="hidden" name
="success_action_redirect"
108 value
="http://[% bucket %].s3.amazonaws.com/restricted/${filename}" />
110 <label
for="colour">Colour
:</label
>
111 <input type
="text" name
="x-amz-meta-colour" id
="colour" value
="green" />
113 <div
class="clearer" />
115 <!-- input needed to have something to upload
. LAST IN FORM
! -->
116 <label
for="file">File
:</label
>
117 <input type
="file" id
="file" name
="file" />
119 <div
class="clearer" />
121 <label
for="submit"></label
>
122 <input type
="submit" id
="submit" name
="submit" value
="Upload!" />