dwilkie / carrierwave_direct

Process your uploads in the background by uploading directly to S3
MIT License
839 stars 181 forks source link

How to customize Content-Disposition? #195

Closed vemv closed 6 years ago

vemv commented 8 years ago

Similar gems let you do the following:

@uploader.add_field('Content-Disposition', 'inline')

I don't see an API to add custom fields to be taken into account by S3?

Cheers - Victor

p8 commented 8 years ago

This should be fixed with #196

vemv commented 8 years ago

Thanks - will try it in production this week!

I'd be good to keep the issue open until we check it works. Then a snippet could be added to the documentation.

vemv commented 8 years ago

I think it'll work fine but I can't check it at the moment (https://github.com/dwilkie/carrierwave_direct/issues/206), will retry later.

In any case, a gem version bump is needed for this feature!

vemv commented 8 years ago

I could try it now. It doesn't work, request will fail with 403:

<Error>
   <Code>AccessDenied</Code>
   <Message>Invalid according to Policy: Policy Condition failed: ["eq", "$response-content-disposition", "inline"]</Message>
   <RequestId>yyyyy</RequestId>
   <HostId>xxxxxx</HostId>
</Error>

This is the relevant ruby code I wrote:

@uploader.policy do |conditions|
  conditions << {"response-content-disposition" => "inline"}
end

Maybe S3 policies really don't have to do with setting content-disposition?

p8 commented 6 years ago

Content-disposition should not be set when uploading. You can pass it to the download url: model.attachment.url(:query => { 'response-content-disposition' => 'attachment' } )