我已经决定使用s3的新服务器端加密,但是我遇到了一个我无法解决的问题。
我使用的是在这里找到的s3 PHP类:https://github.com/tpyo/amazon-s3-php-class
我一直在使用这段代码来放置对象(而且它正在工作):
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,并添加了http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?RESTObjectPUT.html请求头。但是现在,当我试图放置一个对象时,它就会没有错误地失败。
我的新代码是:
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"
));
有没有人尝试过这个新特性,或者谁能在代码中看到错误。
干杯。
发布于 2011-10-07 08:46:32
该标头应该是$metaHeaders数组的一部分,而不是$requestHeaders数组的一部分。
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
发布于 2013-04-25 13:23:26
我们可以使用$s3->create_object($bucket_name,$destination,array( 'acl'=>AmazonS3::ACL_PUBLIC, 'fileUpload' => $file_local, 'encryption'=>"AES256"));下面的代码使用加密方式上传文件
您还可以从这里下载最新的sdk。
发布于 2015-03-02 17:05:35
在官方SDK中:
use Aws\S3\S3Client;
$bucket = '*** Your Bucket Name ***';
$keyname = '*** Your Object Key ***';
// $filepath should be absolute path to a file on disk
$filepath = '*** Your File Path ***';
// Instantiate the client.
$s3 = S3Client::factory();
// Upload a file with server-side encryption.
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $keyname,
'SourceFile' => $filepath,
'ServerSideEncryption' => 'AES256',
));更改现有对象的服务器端加密(复制操作)
use Aws\S3\S3Client;
$sourceBucket = '*** Your Source Bucket Name ***';
$sourceKeyname = '*** Your Source Object Key ***';
$targetBucket = '*** Your Target Bucket Name ***';
$targetKeyname = '*** Your Target Object Key ***';
// Instantiate the client.
$s3 = S3Client::factory();
// Copy an object and add server-side encryption.
$result = $s3->copyObject(array(
'Bucket' => $targetBucket,
'Key' => $targetKeyname,
'CopySource' => "{$sourceBucket}/{$sourceKeyname}",
'ServerSideEncryption' => 'AES256',
));来源:http://docs.aws.amazon.com/AmazonS3/latest/dev/SSEUsingPHPSDK.html
https://stackoverflow.com/questions/7681752
复制相似问题