2012-06-21 2 views
0

콘텐츠 처리 설정이없는 AWS S3 버킷에 수백 개의 객체가 있습니다.Amazon S3에서 기존 객체의 Content-Disposition을 추가하거나 수정하려면 어떻게합니까?

Ruby aws-sdk gem을 사용하고 있습니다.

파일을 다시 업로드하지 않고 이러한 개체에 콘텐츠 처리를 추가하거나 변경하는 방법은 무엇입니까?

나는 또한 copy_to()

obj.write(:content_disposition => 'attachment') 
obj.copy_from(obj.key, :content_disposition => 'attachment') 

을 시도하고있다, move_to(), 그러나이 중 어느 것도 객체에 내용 처리를 추가하는 제대로 작동하지 않습니다. 경우에 따라 개체가 전혀 수정되지 않은 것 같습니다 (수정 시간이 변경되지 않음). 다른 경우 개체 파일이 손상되었습니다!


내가 사용하는 다른 알고 있어요 : response_content_disposition 내용 - 처리 헤더를 설정 HTTP를 통해 S3 객체를 요청

obj.url_for(:read, :response_content_disposition => "attachment") 

감사합니다!

답변

1

aws-sdk 소스 코드를 변경하여 해결책을 찾았습니다. (S3)에서

/s3_object.rb

) (copy_from하는 (방법과 유사한 처리 된 콘텐츠 _) 다음 줄을 추가 S3에서,

if options[:content_disposition] 
    copy_opts[:content_disposition] = options[:content_disposition] 
    copy_opts[:metadata_directive] = "REPLACE" 
end 

도/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) 
관련 문제