在 PHP 中使用 s3 服务器端加密 [英] Using s3 server-side encryption with PHP
问题描述
我决定使用 s3 使用亚马逊新的服务器端加密,但是,我遇到了一个无法解决的问题.
I have decide to avail of amazons new server-side encryption with s3, however, I have run into a problem which I am unable to resolve.
我正在使用此处找到的 s3 PHP 类:https://github.com/tpyo/amazon-s3-php-class
I am using the s3 PHP class found here : https://github.com/tpyo/amazon-s3-php-class
我一直在使用此代码来放置对象(并且它正在工作):
I had been using this code to put objects originally (and it was working) :
S3::putObjectFile($file, $s3_bucket_name, $file_path, S3::ACL_PRIVATE,
array(),
array(
"Content-Disposition" => "attachment; filename=$filename",
"Content-Type" => "application/octet-stream"
)
);
然后我按照这里的指示做了:http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?RESTObjectPUT.html 并添加了x-amz-server-side -encryption"请求标头.但是现在当我尝试放置一个对象时,它会失败而不会出错.
I then did as instructed here : http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?RESTObjectPUT.html and added the 'x-amz-server-side-encryption' request header. But now when I try to put an object it fails without error.
我的新代码是:
S3::putObjectFile($file, $s3_bucket_name, $file_path, S3::ACL_PRIVATE,
array(),
array(
"Content-Disposition" => "attachment; filename=$filename",
"Content-Type" => "application/octet-stream",
"x-amz-server-side-encryption" => "AES256"
)
);
有没有人尝试过这个新功能,或者任何人都可以看到代码中的错误.
Has anybody experimented with this new feature or can anyone see an error in the code.
干杯.
推荐答案
该标头应该是 $metaHeaders
数组的一部分,而不是 $requestHeaders
数组的一部分.
That header should be part of the $metaHeaders
array and not $requestHeaders
array.
S3::putObjectFile($file, $s3_bucket_name, $file_path, S3::ACL_PRIVATE,
array(
"x-amz-server-side-encryption" => "AES256"
),
array(
"Content-Disposition" => "attachment; filename=$filename",
"Content-Type" => "application/octet-stream"
)
);
这是文档中的方法定义:
putObject (mixed $input,
string $bucket,
string $uri,
[constant $acl = S3::ACL_PRIVATE],
[array $metaHeaders = array()],
[array $requestHeaders = array()])
<小时>
您也可以考虑使用 PHP SDK?
这篇关于在 PHP 中使用 s3 服务器端加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!