ruby on rails - Carrierwave: Process Temp file and then upload via fog -


i processing pdf uploaded user extracting text , saving output in text file processing later.

locally store pdf in public folder when work on heroku need use s3.

i thought pdf path problem, included

if rails.env.test? || rails.env.cucumber?

but still receive

argumenterror (input must io-like object or filename):

is there way of temporarily storing pdf in root/tmp folder on heroku, text it, , after done, upload document s3?

def convert_pdf     if rails.env.test? || rails.env.cucumber?         pdf_dest = file.join(rails.root, "public", @application.document_url)     else         pdf_dest = @application.document_url     end     txt_file_dest = rails.root + 'tmp/pdf-parser/text'      document_file_name = /\/uploads\/application\/document\/\d{1,}\/(?<file_name>.*).pdf/.match(@application.document_url)[:file_name]      pdf::reader.open(pdf_dest) |reader|         file.open(file.join(txt_file_dest, document_file_name + '.txt'), 'w+') |f|             reader.pages.each |page|                 f.puts page.text             end         end     end end 

you're going want set custom processor in uploader. , on top of that, since output file (.txt) isn't going have same extension input file (.pdf), you're going want change filename. following belongs in uploader:

process :convert_to_text  def convert_to_text   temp_dir = rails.root.join('tmp', 'pdf-parser', 'text')   temp_path = temp_dir.join(filename)    fileutils.mkdir_p(temp_dir)    pdf::reader.open(current_path) |pdf|     file.open(temp_path, 'w') |f|       pdf.pages.each |page|         f.puts page.text       end     end   end    file.unlink(current_path)   fileutils.cp(temp_path, current_path) end  def filename   super + '.txt' if original_filename.present? end 

i haven't run code, there bugs, should give idea @ least.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -