Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the real file from S3 using CarrierWave

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?

like image 627
Luiz E. Avatar asked Aug 11 '12 19:08

Luiz E.


1 Answers

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

like image 187
Zachary Anker Avatar answered Nov 19 '22 09:11

Zachary Anker