douyujun0152 2013-06-07 20:23
浏览 87
已采纳

如何在PHP中使用Amazon S3 UploadBuilder时设置存储类

I'm using the PHP SDK 2 for Amazon S3, in particular the UploadBuilder class to do multipart concurrent uploading of files. How, if you can, do you set the storage class of the file that you are uploading? When you do a regular putObject, you can set the storage class that you want the file to have. I want my files to be stored using reduced redundancy rather than the standard storage. Can I just use setOption to set a header like so?

setOption('x-amz-storage-class', 'REDUCED_REDUNDANCY')

From looking at the source of UploadBuilder it appears you may be able to set it using Metadata. Here's an example of setting an MD5 header from the source:

// If an MD5 is specified, then add it to the custom headers of the request
// so that it will be returned when downloading the object from Amazon S3
if ($this->md5) {
    $params['Metadata']['x-amz-Content-MD5'] = $this->md5;
}

So, that would mean I would set it doing something like this:

setOption('Metadata', array('x-amz-storage-class' => 'REDUCED_REDUNDANCY'))

Can anyone confirm this is correct or am I way off base?

  • 写回答

1条回答 默认 最新

  • doulouli8686 2013-06-08 14:41
    关注

    In the API docs for setOption, it says that the method sets "an option to pass to the initial CreateMultipartUpload operation". According to the API docs for createMultipartUpload, you should use the StorageClass param. So, you should be able to do the following with the UploadBuilder to set the storage class on your multipart upload:

    ->setOption('StorageClass', 'REDUCED_REDUNDANCY')

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题