我正在使用 Rails 3、Paperclip(3.3.0)、aws-sdk (1.7.1)。
我的回形针附件安全地存储在 S3 上。
附件.rb
has_attached_file :attachment,
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:s3_protocol => 'https',
:s3_permissions => :private, # Sets the file, not the folder as private in S3
:use_timestamp => false,
:default_style => :original, # NEEDS to be original or download_url method below wont work
:default_url => '/images/:attachment/default_:style.png',
:path => "/:rails_env/private/s/:s_id/uuploaded_files/:basename.:extension"
为了下载文件,我生成了一个安全 URL,如下所示:
def authenticated_url(style = nil, expires_in = 1.hour)
mime_type = MIME::Types.type_for(self.attachment_file_name)[0]
attachment.s3_object(style).url_for(:read, :secure => true, :response_content_type => mime_type.to_s, :expires => expires_in).to_s
end
问题在于 PSD:这是返回空的:
Rails MIME::Types.type_for('photoshop_1354320001.psd')
在代码中它看起来像:
mime_type = MIME::Types.type_for(self.attachment_file_name)[0]
它适用于其他文件,但不适用于 PSD。知道为什么以及如何解决吗?
谢谢