简体   繁体   English

如何使用Perl将图像上传到Amazon S3?

[英]How To Upload Images to Amazon S3 Using Perl?

I'm trying to upload files to S3 using Perl. 我正在尝试使用Perl将文件上传到S3。

According to this module: 根据这个模块:

http://metacpan.org/pod/Amazon::S3::Bucket 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? 但是,如何将图像(GIF,JPEG,PNG)上传到S3?

Thanks, 谢谢,

Linda 琳达

That code won't upload the file - it's simply setting the value associated with the key "testing.txt" to "T". 该代码不会上传文件 - 它只是将与“testing.txt”键相关联的值设置为“T”。 If you want to upload a file you could use the add_key_filename method: 如果要上传文件,可以使用add_key_filename方法:

The method works like add_key except the value is assumed to be a filename on the local file system. 该方法的作用类似于add_key,但该值假定为本地文件系统上的文件名。 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. 根据需要调整内容类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM