Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

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

Open
hidr0 opened this issue Feb 19, 2018 · 1 comment
Open

Comments

@hidr0
Copy link

hidr0 commented Feb 19, 2018

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
Copy link
Author

hidr0 commented Feb 19, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant