Skip to content

Instantly share code, notes, and snippets.

@emirikol
Created August 3, 2014 15:45
Show Gist options
  • Save emirikol/c6942401148a05c7ef18 to your computer and use it in GitHub Desktop.
Save emirikol/c6942401148a05c7ef18 to your computer and use it in GitHub Desktop.
saving paperclip string directly
#option A)
stream = StringIO(string)
stream.content_type = 'application/pdf' #paperclip adds silly attr accessors to StringIO that we need to pass validations
#stream.original_filename = "anything.pdf" #if needed...
signed_pdf_document.original_pdf = stream
signed_pdf_document.save
#option B)
file = Tempfile.new( ["file_name", '.pdf'] )
file.write( string )
signed_pdf_document.attachment = file
signed_pdf_document.save
#will probably work:
signed_pdf = business.sign_document(pdf_string)
stream = StringIO.new
signed_pdf.write(stream)
stream.content_type = 'application/pdf'
signed_pdf_document.original_pdf = stream
signed_pdf_document.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment