当前位置:Gxlcms > mysql > 使用perl上传文件到S3,并设置http的header

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

时间:2021-07-01 10:21:17 帮助过:38人阅读

这段时间要忙迁移公司的业务到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 @ARGV<1;

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




相关资料:

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

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

人气教程排行