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')

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

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样