我目前正在使用carrierwave,我想知道以下是否可能。如果是这样的话!提前致谢
我有一个用户,想要上传头像,然后会创建以下文件夹
public/image/avatar/customer.id/image01/small
public/image/avatar/customer.id/image01/normal
public/image/avatar/customer.id/image01/big
public/image/avatar/customer.id/image02/small
public/image/avatar/customer.id/image02/normal
public/image/avatar/customer.id/image02/big
基本上,我不想覆盖以前的图像我想要保留它们,但是为最新图片创建一个文件夹以便将它保存在那里。还希望客户ID有一条路径。
感谢。 PS:如果可能的话,请提供一个教程或一些,如果不可能,回形针允许吗?谢谢,我似乎找不到任何关于它的东西。
答案 0 :(得分:0)
<强>上传/ image_uploader.rb 强>
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"public/image/avatar/#{current_user.id}"
end
version :small do
end
version :normal do
end
version :big do
end
end
您的图片上传器应该是这样的。