【问题标题】:How to get the real file from S3 using CarrierWave如何使用 CarrierWave 从 S3 获取真实文件
【发布时间】:2012-08-08 15:54:06
【问题描述】:

我有一个应用程序可以读取文件的内容并为其编制索引。我将它们存储在磁盘本身中,但现在我使用的是 Amazon S3,因此以下方法不再适用。

原来是这样的:

def perform(docId)
    @document = Document.find(docId)
    if @document.file?

      #You should't create a new version
      @document.versionless do |doc|
        @document.file_content = Cloudoc::Extractor.new.extract(@document.file.file)
        @document.save
      end

    end
  end

@document.file 返回FileUploaderdoc.file.file 返回CarrierWave::Storage::Fog::File 类。

我怎样才能得到真正的文件?

【问题讨论】:

    标签: ruby ruby-on-rails-3 amazon-s3 carrierwave


    【解决方案1】:

    调用@document.file.read 将获得来自 Carrierwave 中 S3 的文件内容。

    【讨论】:

    • Jacob,来自carrierwave google 小组,也用open(@document.file.url) 解决了
    • @document.file.read 可能更好,因为无论使用什么文件存储,它都可以工作,即它适用于本地文件系统和 S3。
    • .read 对我们不起作用(我们将 cloudinary 与carrierwave 结合使用)
    • 嗨@Zachary,如果我使用 @document.file.read,我得到 指定的密钥不存在,你能帮帮我吗有了这个。
    猜你喜欢
    • 1970-01-01
    • 2012-10-31
    • 2020-12-01
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    • 2016-11-13
    相关资源
    最近更新 更多