How to get the real file from S3 using CarrierWave

一个人想着一个人 提交于 2019-12-10 13:46:26

问题


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.

It was something like this:

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 returns the FileUploader, and doc.file.file returns the CarrierWave::Storage::Fog::File class.

How can I get the real file?


回答1:


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



来源:https://stackoverflow.com/questions/11917027/how-to-get-the-real-file-from-s3-using-carrierwave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!