如何使用CarrierWave从S3获取真实文件 [英] How to get the real file from S3 using CarrierWave

查看:92
本文介绍了如何使用CarrierWave从S3获取真实文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an application that reads the content of a file and indexes it. I was storing them in the disk itself, but now I'm using Amazon S3, so the following method doesn't work anymore.

是这样的:

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类.

如何获取真实文件?

推荐答案

调用@document.file.read将使您从Carrierwave的S3中获取文件的内容.

Calling @document.file.read will get you the contents of the file from S3 in Carrierwave.

这篇关于如何使用CarrierWave从S3获取真实文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆