Luiz E. Luiz E. - 7 months ago 24
Ruby Question

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?

Answer

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