停止 Carrierwave 缓存存储信息

Stop Carrierwave from Caching Storage Information

Carrierwave 正在缓存 Azure 存储信息并将文件上传到错误的容器。

例如,如果我将图像上传到容器 "a",然后尝试将图像上传到容器 "b",它仍然会上传到容器 "a"。我假设 Carrierwave 在某处缓存存储信息,而不是在每次上传时设置容器信息。我如何阻止它这样做?

class FileUploader < CarrierWave::Uploader::Base

storage :azure

def initialize(*)
super
  CarrierWave.configure do |config|
    config.azure_storage_account_name = account_name
    config.azure_storage_access_key = storage_key
    config.azure_container = model.container_name
  end
end

我也尝试过为每次上传重新初始化上传器,但我仍然遇到同样的问题。

uploader = FileUploader.new
uploader.store!(file)

想通了。不要将配置属性分配给 CarrierWave,而是将它们分配给初始化的上传器对象。

def initialize(*)
  super
  self.azure_storage_account_name = account_name
  self.azure_storage_access_key = storage_key
  self.azure_container = model.container_name
end