ssc*_*rus 4 ruby-on-rails amazon-s3 paperclip ruby-on-rails-3
我有一个模型将图像和pdf上传到Amazon S3 - 图像工作,pdf没有.
这就是我的模型:
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png', 'image/gif']
has_attached_file :pdf,
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:path => "/userpdfs/:id/:basename.:extension"
has_attached_file :photo,
:styles => {:medium => "200x300>", :thumb => "100x150>" },
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:path => "/userphotos/:style/:id/:basename.:extension"
Run Code Online (Sandbox Code Playgroud)
亚马逊正在展示userphotos但没有userpdfs.两种类型在我的数据库中都有四个字段:
pdf_name
pdf_type # could also be a word doc
pdf_size
pdf_updated_at
Run Code Online (Sandbox Code Playgroud)
将任何图像上传到:pdf字段都可以!关于pdfs本身的一些东西似乎搞乱了系统.我的服务器说它已将文件保存到S3但它们没有出现在目录中.
PDF现在只有在标题中没有空格时才起作用.有了空格,我收到以下错误:Errno::EPIPE: Broken Pipe.
试试这个
>> Attachment.last.file_path
=> "https://s3.amazonaws.com/content.dynamixccw.com/attachments/4/Financial goal Report.pdf"
>> url = _
=> "https://s3.amazonaws.com/content.dynamixccw.com/attachments/4/Financial goal Report.pdf"
>> url.gsub(' ', '%20')
=> "https://s3.amazonaws.com/content.dynamixccw.com/attachments/4/Financial%20goal%20Report.pdf"
Run Code Online (Sandbox Code Playgroud)
要验证,请将其丢弃
validates_attachment_content_type :pdf, :content_type => ['application/pdf', 'application/msword', 'text/plain'], :if => :pdf_attached?
def pdf_attached?
self.pdf.file?
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11782 次 |
| 最近记录: |