Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8514573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:54:28+00:00 2026-06-11T04:54:28+00:00

I’ve been fighting this for some time now, and your help will certainly be

  • 0

I’ve been fighting this for some time now, and your help will certainly be of much appreciation.

I’ve built a method to sign pdf documents which you can find here, and now am only one step away from signing my file.

I would like to do this asynchronously, but first i would need to understand how to do it synchronously.

So I try 2 different approaches, the after post_process :

after_post_process do |receipt|
    if receipt.receipt_file_changed?

      require 'aws-sdk'
          logger.debug("RECEIPT ID: #{self.inspect}")
          file = receipt.receipt_file.queued_for_write[:original]
          s3=AWS::S3.new(
          access_key_id: S3_CONFIG["access_key_id"],
          secret_access_key: S3_CONFIG["secret_access_key"])
          bucket_name = S3_CONFIG["bucket"]

          b = s3.buckets[bucket_name]
          filen = File.basename(file.path)
          outputF = "original/teste.pdf"

          o = b.objects[outputF]
          o.write(file: file.path)

    end
  end

where i wanted to be able to send the file to a path something like /original/1/myfilename.pdf where 1 would be my receipt_id (and is null at the time of the after post_process).

I then tried a different approach with after_save, but receipt_file.to_file(:original) is not a valid call…

after_save do |receipt|
    if receipt.receipt_file_changed?

      require 'aws-sdk'
          logger.debug("RECEIPT ID: #{receipt.inspect}")

          s3=AWS::S3.new(
          access_key_id: S3_CONFIG["access_key_id"],
          secret_access_key: S3_CONFIG["secret_access_key"])
          bucket_name = S3_CONFIG["bucket"]

          b = s3.buckets[bucket_name]
          filen = File.basename(receipt_file_file_name)
          outputF = "original/teste.pdf"

          o = b.objects[outputF]
          o.write(file: receipt.receipt_file.to_file(:original))

    end
  end

How can i get the file and upload it back again to S3 ?

Edit

After some research i read how we can load a file from Amazon, and now the problem is that my file content is empty…What am i doing wrong?

after_save do |receipt|
    if receipt.receipt_file_changed?

      require 'aws-sdk'

          logger.debug("I was here inside after_save")
          s3=AWS::S3.new(
          access_key_id: S3_CONFIG["access_key_id"],
          secret_access_key: S3_CONFIG["secret_access_key"])
          bucket_name = S3_CONFIG["bucket"]

          b = s3.buckets[bucket_name]
          filen = File.basename(receipt_file_file_name)
          logger.debug("Filename is #{filen}")
          path = "original/#{receipt.id}/#{filen}"
          o = b.objects[path]

          require 'tempfile'

          ext= File.extname(filen)

          file = Tempfile.new([File.basename(filen,ext),ext], :encoding => 'ascii-8bit')
          # streaming download from S3 to a file on disk

          begin
            o.read do |chunk|
                file.write(chunk)
            end
          end
          file.close

          logger.debug("File is #{file.inspect}")

          o.write(file: signPdf(file).path)
          file.unlink

    end
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:54:30+00:00Added an answer on June 11, 2026 at 4:54 am

    After splitting this problem in pieces, i noticed the real problem was within the process of download and writing to local disk. So i asked this question, and reached for a workaround.
    In the end got this code for the after save :

      after_save do |receipt|
        if receipt.receipt_file_changed? && !@receipt.receipt_file.url[".pdf"] 
    
          require 'aws-sdk'
    
              s3=AWS::S3.new(
              access_key_id: S3_CONFIG["access_key_id"],
              secret_access_key: S3_CONFIG["secret_access_key"])
              bucket_name = S3_CONFIG["bucket"]
    
              b = s3.buckets[bucket_name]
              filen = File.basename(receipt_file_file_name)
    
              path = "original/#{receipt.id}/#{filen}"
              o = b.objects[path]
    
              require 'open-uri'
              require 'tempfile'
    
              ext= File.extname(filen)
              tfile = Tempfile.new([File.basename(filen,ext),ext])
              begin
                open(tfile.path,"wb") do |file|
                    file << open(receipt.receipt_file.url,:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read
                    o.write(file: signPdf(file).path, :acl => :public_read)
                end
              ensure
                tfile.close!
              end
    
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.