【发布时间】:2014-08-01 01:17:16
【问题描述】:
我正在使用 Paperclip 和 Carrierwave 将图像上传到 S3。目前,某个模型的图像正在上传到存储桶根目录中的一个无名文件夹。如何确保他们上传到的文件夹没有空名称?这是 Paperclip/Carrierwave 初始化程序中的相关代码
fog_credentials = {
:provider => "AWS",
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
}
# Carrierwave
config.storage = :fog
config.fog_credentials = fog_credentials
config.fog_directory = ENV['AWS_S3_BUCKET']
config.fog_public = true
# Paperclip
Paperclip::Attachment.default_options[:storage] = :fog
Paperclip::Attachment.default_options[:fog_credentials] = fog_credentials
Paperclip::Attachment.default_options[:fog_directory] = ENV['AWS_S3_BUCKET']
Paperclip::Attachment.default_options[:fog_host] = ENV['AWS_S3_ASSET_HOST']
Paperclip::Attachment.default_options[:url] = ":class/:id_partition/:attachment/:style/:filename"
Paperclip::Attachment.default_options[:path] = ":url"
**已编辑**
我忘了提到我正在使用spree,它似乎在某个地方重写了这些选项。
我通过显式设置更改了 URL 和路径选项
Spree::Image.attachment_definitions[:attachment][:url] = "spree/products/:id/:style/:basename.:extension"
Spree::Image.attachment_definitions[:attachment][:path] = "spree/products/:id/:style/:basename.:extension"
其默认值都以斜线为前缀。根据这个paperclip-aws gem,在这些选项前面加上斜线将在存储桶的根目录中创建一个无名文件夹。
【问题讨论】:
-
你提到你正在使用这两种宝石 - 有什么特别的原因吗?我会坚持使用
paperclip
标签: ruby-on-rails amazon-s3 paperclip carrierwave filepath