简体   繁体   English

带有文件上传/下载的 Rails 3 Paperclip

[英]Rails 3 Paperclip with file upload/downloads

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.我有一个 rails 3 应用程序,它允许用户通过回形针将文件上传到 Amazon s3 来共享文件,我想允许其他用户下载这些文件。 However, some sort of post-processing seems to be going on with this file somewhere between my app and Amazon s3.但是,在我的应用程序和 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.这很好用,但是如果我实际上是 go 到亚马逊 s3 开发人员工具,那么该文件的 url 似乎是: Z80791B3AE7002CB88C246876原始名称或原始名称或没有原始名称或测试类型://s3.com。

I then tried using something like this: [p.attachment.url(:original, false), p.attachment_file_name].join("/")然后我尝试使用这样的东西: [p.attachment.url(:original, false), p.attachment_file_name].join("/")

which yields: http://s3.amazonaws.com/test_development/1/original/test.pdf产生: http://s3.amazonaws.com/test_development/1/original/test.pdf

However if I got to this url I get a cryptic xml error:但是,如果我遇到这个 url 我会得到一个神秘的 xml 错误:

<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?我只想将文件上传到 s3 而不进行任何处理,然后稍后再下载..我应该如何 go 这样做?

Thanks!谢谢!

The :path option is is used as the full filename. :path选项用作完整的文件名。 Nothing is added, it's only interpolated.什么都没有添加,它只是插值。 Try :path => ':id/:style/:basename.:extension' .试试:path => ':id/:style/:basename.:extension'

And when you change :path , you often have to change :url also.当您更改:path时,您通常也必须更改:url

More infos:更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM