在PHP中使用s3服务器端加密 [英] Using s3 server-side encryption with PHP

查看:160
本文介绍了在PHP中使用s3服务器端加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定使用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"
     )
);

这是 docs :

putObject (mixed $input, 
           string $bucket, 
           string $uri, 
           [constant $acl = S3::ACL_PRIVATE], 
           [array $metaHeaders = array()], 
           [array $requestHeaders = array()])


您还可以考虑使用 SDK for PHP ?

这篇关于在PHP中使用s3服务器端加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆