Use Perl to upload files to S3 and set headers for HTTP

Source: Internet
Author: User
Keywords Nbsp; http upload file name
Tags business business to company connect data developer download file
This period of time to move the company's business to AWS, on the first simple write some, specific time to add ...





first need to download S3 related Perl pm:http://developer.amazonwebservices.com/connect/entry.jspa?externalid=133& categoryid=47





#!/usr/bin/perl

# Stencils connects to I 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 "moment-in 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;




when used:./PUT_OBJ_S3 test.jpg &lt;/home/test.jpg
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.