I have a rails 3 app that allows users to share files by uploading them to Amazon s3 via paperclip, and I want to allow others users to download these files. However, some sort of post-processing seems to be going on with this file somewhere between my app and Amazon s3.
Here’s my code:
has_attached_file :attachment,
:storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ':id/:style', :bucket => "test_development"
This works fine, however if I actually go to the amazon s3 developer tools the url for the file just seems to be: http://s3.amazonaws.com/test_development/1/original without the original name or type.
I then tried using something like this: [p.attachment.url(:original, false), p.attachment_file_name].join("/")
which yields: http://s3.amazonaws.com/test_development/1/original/test.pdf
However if I got to this url I get a cryptic xml error:
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>1/original/About Downloads.pdf</Key>
<RequestId>7E5CC6A01CADF831</RequestId>
<HostId>
4ruFf0JtdalnaIE/SHUAqT8hVYEda9Ul6gxNmYTIAniw7piTN+Q16uKKCzi9yezl
</HostId>
</Error>
What am I doing wrong here? I just want to upload the file to s3 without any sort of processing then download again later..how should I go about doing this?
Thanks!
The
:pathoption is is used as the full filename. Nothing is added, it’s only interpolated. Try:path => ':id/:style/:basename.:extension'.And when you change
:path, you often have to change:urlalso.More infos: