jrgifford / delayed_paperclip

Process your Paperclip attachments in the background with delayed_job or Resque.
http://www.jstorimer.com/ruby/2010/01/30/delayed-paperclip.html
MIT License
404 stars 155 forks source link

Linking existing S3 object to Paperclip does not trigger Delayed::Job #213

Open hidr0 opened 6 years ago

hidr0 commented 6 years ago

Hello,

I am trying to upload multiple images using the client side, and after that linking them with paperclip.

I am using s3_direct_upload which gives me the url where the image has been uploaded to s3, then I can then find out where Paperclip is going to search for the image, so it can reprocess it. I copy the image to that location. And expect delayed_paperclip to add to the Dalyed:Job queue, but it doesn't.

def ....

uploaded_file_url = params[:url].gsub("%2F", "/")

getting the location of the picture

filename = File.basename(uploaded_file_url) filetype = "image/jpeg"

id = ContentPicture.maximum(:id).try(:next) || 1 content_picture = ContentPicture.new(id: id, picture_file_name:filename, picture_content_type:filetype)

ActiveRecord::Base.transaction do credentials = Aws::Credentials.new Rails.application.config.aws[:access_key_id], Rails.application.config.aws[:secret_access_key]

s3 = Aws::S3::Client.new(region: Rails.application.config.aws[:region], credentials: credentials)

s3.copy_object({bucket: Rails.application.config.paperclip_defaults[:s3_credentials][:bucket], copy_source:uploaded_file_url , key: content_picture.picture.path ,acl: "public-read"})
#setting up and copying the picture where content_picture.picture.url is looking for.

end instance.content_pictures << content_picture

And with this I have no Delayed::Job to execute.

I have to do content_picture.picture.reprocess! which downloads and reuploads the picture to S3. I have the uploading handled on the client side and I only want to execute the delayed job which will download the picture, process it and upload it where it needs to be.

hidr0 commented 6 years ago

I dug a little and found some kind of fix:

DelayedPaperclip.enqueue(cc.class.to_s, cc.id, :picture)

where cc is the instance of the ContentPicture, which is the object that has the attached_file.