<span><span>#!/usr/bin/perl<br>
</span>
<br>
<span># Simply connects to my S3 account, creates a new bucket</span><br>
<span># and uploads a file called logo.jpg (passed thru STDIN) with</span><br>
<span># public-read acl set<br>
</span><br>
<br>
<br>
<span>use</span> strict<span>;</span><br>
<span>use</span> warnings<span>;</span><br>
<br>
<span>print</span> <span>"you must specil file name for KEY\n"</span> <span>if</span> <span>@</span><span>ARGV</span><span>1<span>;</span><br>
<br>
<span>use</span> S3<span>;</span><br>
<span>use</span> S3<span>:</span><span>:</span>AWSAuthConnection<span>;</span><br>
<span>use</span> S3<span>:</span><span>:</span>QueryStringAuthGenerator<span>;</span><br>
<br>
<span>my</span> <span>$</span><span>AWS_ACCESS_KEY_ID</span> <span>=</span> <span>'1DQ5TN5665Z7TVDNN682'</span><span>;</span><br>
<span>my</span> <span>$</span><span>AWS_SECRET_ACCESS_KEY</span> <span>=</span> <span>'CZpPQc55S2zF8JXwfME4JUOhpB9h4pQgTiGBF3sE'</span><span>;</span><br>
<span>my</span> <span>$</span><span>BUCKET_NAME</span> <span>=</span> <span>'squidwm'</span> <span>;</span><br>
<span>my</span> <span>$</span><span>KEY</span><span>=</span><span>$</span><span>ARGV</span><span>[</span>0<span>]</span><span>;</span><br>
<br>
<span>#my @file_name_for_key=split/\//,"$ARGV[0]";</span><br>
<span>#my $KEY = pop @file_name_for_key;</span><br>
<span>#print $KEY;<br>
</span>
<br>
<span>my</span> <span>%</span><span>headers</span> <span>=</span> <span>(</span><br>
<span>'x-amz-acl'</span> <span>=</span><span>></span> <span>'public-read'</span><span>,</span><span>'Cache-Control'</span><span>=</span><span>></span><span>'24342'</span><span>,</span><br>
<span>)</span><span>;</span><br>
<br>
<span>my</span> <span>$</span><span>conn</span> <span>=</span><br>
S3<span>:</span><span>:</span>AWSAuthConnection<span>-</span><span>></span>new<span>(</span><span>$</span><span>AWS_ACCESS_KEY_ID</span><span>,</span> <span>$</span><span>AWS_SECRET_ACCESS_KEY</span><span>)</span><span>;</span><br>
<span>my</span> <span>$</span><span>generator</span> <span>=</span><br>
S3<span>:</span><span>:</span>QueryStringAuthGenerator<span>-</span><span>></span>new<span>(</span><span>$</span><span>AWS_ACCESS_KEY_ID</span><span>,</span> <span>$</span><span>AWS_SECRET_ACCESS_KEY</span><span>)</span><span>;</span><br>
<br>
<span>print</span> <span>$</span><span>conn</span><span>-</span><span>></span>create_bucket<span>(</span><span>$</span><span>BUCKET_NAME</span><span>)</span><span>-</span><span>></span>message<span>,</span> <span>"\n"</span><span>;</span><br>
<br>
<span>my</span> <span>$</span><span>data</span> <span>;</span><br>
FILE<span>:</span> <span>while</span><span>(</span>1<span>)</span> <span>{</span><br>
<span>my</span> <span>$</span><span>n</span> <span>=</span> <span>sysread</span><span>(</span><span>STDIN</span><span>,</span> <span>$</span><span>data</span><span>,</span> 1024 <span>*</span> 1024<span>,</span> <span>length</span><span>(</span><span>$</span><span>data</span><span>)</span><span>)</span><span>;</span><br>
<span>if</span> <span>(</span><span>$</span><span>n</span> <span> 0<span>)</span> <span>{</span><br>
<span>print</span> <span>STDERR</span> <span>"Error reading input: $!\n"</span><span>;</span><br>
<span>exit</span> 1<span>;</span></span></span></span>
|