【问题标题】:Stop Carrierwave from Caching Storage Information停止 Carrierwave 缓存存储信息
【发布时间】:2017-07-20 00:44:11
【问题描述】:

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)

【问题讨论】:

    标签: ruby-on-rails ruby azure caching carrierwave


    【解决方案1】:

    想通了。而不是将配置属性分配给 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-11
      • 1970-01-01
      • 2013-11-16
      • 2011-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多