The paper clip processor runs on S3

I am trying to create a custom Paperclip::Processorone that integrates with an external web service (the processor will call the web service whenever a new file is uploaded). An external service needs a file that must be present in S3 and will automatically download the processed versions to S3.

Can this be done using custom Paperclip::Processoror should it be done using an ActiveRecord callback? If a Paperclip::Processorwill work, what is the best way to start the download? Ideally, I would like to make a processor, but the requirement is that the original MUST file is loaded first on S3. I looked at the use of calls after_create, but sometimes it conflicts with after_createthat used in paperclip. Thank.

+3
source share
2 answers

You can do this to create a local copy of the file. If it is on S3 will be loaded.

tmp_file = @model.attached_file.to_file => TempFile<...>

Then you can perform operations on this TempFile. When you don:

@model.attached_file = tmp_file
@model.save

Edit: read your question incorrectly. You can use the hooks before_post_processand after_post_processto perform tasks before or after the file processing.

class Model < AR::Base
  has_attached_file :avatar

  after_post_process :ping_webservice

  private

  def ping_webservice
    # Do your magic here.
  end
end
+3
source

Recently, I have encountered a similar problem, and it is with the after_save callback. I managed to fix my problem by specifying paperclip (has_attached_file ...) after I defined my after_save. So the paperclip callback will fire after mine.

+2
source

Source: https://habr.com/ru/post/1775158/


All Articles