title: How to handle a file_as_string (generated by Prawn) so that it is accepted by Carrierwave?
body: <p>I'm using Prawn to generate a PDF from the controller of a Rails app,</p>
  
  <pre><code>...
  respond_to do |format|
    format.pdf do
      pdf = GenerateReportPdf.new(@object, view_context)
      send_data pdf.render, filename: "Report", type: "application/pdf", disposition: "inline"
    end
  end
  </code></pre>
  
  <p>This works fine, but I now want to move GenerateReportPdf into a background task, and pass the resulting object to Carrierwave to upload directly to S3.</p>
  
  <p>The worker looks like this</p>
  
  <pre><code>def perform
    pdf           = GenerateReportPdf.new(@object)
    fileString    = ???????
    document      = Document.new(
      object_id: @object.id,
      file: fileString )
      # file is field used by Carrierwave 
  end
  </code></pre>
  
  <p>How do I handle the object returned by Prawn (<code>?????</code>) to ensure it is a format that can be read by Carrierwave.</p>
  
  <p><code>fileString = pdf.render_file 'filename'</code> writes the object to the root directory of the app. As I'm on Heroku this is not possible. </p>
  
  <p><code>file = pdf.render</code> returns <code>ArgumentError: string contains null byte</code></p>
  
  <p><code>fileString = StringIO.new( pdf.render_file 'filename' )</code> returns <code>TypeError: no implicit conversion of nil into String</code></p>
  
  <p><code>fileString = StringIO.new( pdf.render )</code> returns <code>ActiveRecord::RecordInvalid: Validation failed: File You are not allowed to upload nil files, allowed types: jpg, jpeg, gif, png, pdf, doc, docx, xls, xlsx</code></p>
  
  <p><code>fileString = File.open( pdf.render )</code> returns <code>ArgumentError: string contains null byte</code></p>
  
  <p>....and so on.</p>
  
  <p>What am I missing? <code>StringIO.new( pdf.render )</code> seems like it should work, but I'm unclear why its generating this error. </p>