我们通过更改aws-sdk源代码找到了解决方案。
在 s3/s3_object.rb 中
将以下行添加到 copy_from() (类似于 :content_type 的处理方式)
if options[:content_disposition]
copy_opts[:content_disposition] = options[:content_disposition]
copy_opts[:metadata_directive] = "REPLACE"
end
另外,在 s3/client.rb 中
添加下面标记的行
object_method(:copy_object, :put,
:header_options => {
:copy_source => 'x-amz-copy-source',
:cache_control => 'Cache-Control',
:metadata_directive => 'x-amz-metadata-directive',
:storage_class => 'x-amz-storage-class',
:server_side_encryption => 'x-amz-server-side-encryption',
:content_type => 'Content-Type',
:content_disposition => 'Content-Disposition', # add this line here
}) do
完成上述操作后,您可以执行以下操作将内容配置添加到现有对象:
obj.copy_from(obj.key, :content_disposition => 'attachment', :content_type => 'image/png', :acl => :public_read)