欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

使用perl上传文件到S3,并设置http的header

程序员文章站 2022-05-16 16:36:34
...

这段时间要忙迁移公司的业务到AWS,上,先简单的写一些,具体的有时间再补充了.... 首先需要下载S3的相关的perl的pm: http://developer.amazonwebservices.com/connect/entry.jspa?externalID=133categoryID=47 #!/usr/bin/perl # Simply connects to my S3


这段时间要忙迁移公司的业务到AWS,上,先简单的写一些,具体的有时间再补充了....


首先需要下载S3的相关的perl的pm:

http://developer.amazonwebservices.com/connect/entry.jspa?externalID=133&categoryID=47


#!/usr/bin/perl

# Simply connects to my S3 account, creates a new bucket
# and uploads a file called logo.jpg (passed thru STDIN) with
# public-read acl set



use strict;
use warnings;

print "you must specil file name for KEY\n" if @ARGV1;

use S3;
use S3::AWSAuthConnection;
use S3::QueryStringAuthGenerator;

my $AWS_ACCESS_KEY_ID = '1DQ5TN5665Z7TVDNN682';
my $AWS_SECRET_ACCESS_KEY = 'CZpPQc55S2zF8JXwfME4JUOhpB9h4pQgTiGBF3sE';
my $BUCKET_NAME = 'squidwm' ;
my $KEY=$ARGV[0];

#my @file_name_for_key=split/\//,"$ARGV[0]";
#my $KEY = pop @file_name_for_key;
#print $KEY;

my %headers = (
    'x-amz-acl' => 'public-read','Cache-Control'=>'24342',
);

my $conn =
    S3::AWSAuthConnection->new($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY);
my $generator =
    S3::QueryStringAuthGenerator->new($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY);

print $conn->create_bucket($BUCKET_NAME)->message, "\n";

my $data ;
FILE: while(1) {
    my $n = sysread(STDIN, $data, 1024 * 1024, length($data));
    if ($n 0) {
        print STDERR "Error reading input: $!\n";
        exit 1;


使用时: ./put_obj_s3 test.jpg /test.jpg




相关资料:

http://www.perl.com/lpt/a/1002

http://docs.amazonwebservices.com/AmazonS3/latest/gsg/