Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Upload Images to Amazon S3 Using Perl?

I'm trying to upload files to S3 using Perl.

According to this module:

http://metacpan.org/pod/Amazon::S3::Bucket

...the following code will upload text files:

# create resource with meta data (attributes)
my $keyname = 'testing.txt';
my $value   = 'T';
$bucket->add_key(
   $keyname, $value,
   {   content_type        => 'text/plain',
       'x-amz-meta-colour' => 'orange',
   }
);

However, how do you upload images (GIF, JPEG, PNG) to S3?

Thanks,

Linda

like image 551
Linda Avatar asked Dec 20 '22 15:12

Linda


1 Answers

That code won't upload the file - it's simply setting the value associated with the key "testing.txt" to "T". If you want to upload a file you could use the add_key_filename method:

The method works like add_key except the value is assumed to be a filename on the local file system. The file will be streamed rather then loaded into memory in one big chunk.

Something like:

$bucket->add_key_filename(
    'image-key.jpg',
    'local-filename.jpg',
    {
        content_type => 'image/jpeg',
    }
);

Adjust the content type as required.

like image 87
martin clayton Avatar answered Jan 08 '23 00:01

martin clayton