我使用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,使用斜杠为这些选项添加前缀将在存储桶的根目录中创建无名文件夹。
答案 0 :(得分:1)
我忘了提到我使用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,使用斜杠为这些选项添加前缀将在存储桶的根目录中创建无名文件夹。