好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

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


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


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

http://developer.amazonwebservices测试数据/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://HdhCmsTestperl测试数据/lpt/a/1002

http://docs.amazonwebservices测试数据/AmazonS3/latest/gsg/

查看更多关于使用perl上传文件到S3,并设置http的header的详细内容...

  阅读:36次