Using a Delayed Staple Direct Load S3

I am using Delayed Paperclip along with direct download to S3. My model is called Photo

, and its attachment image

.

Images are uploaded to S3 using JavaScript from the Photos form. The file is stored in the folder where Paperclip expects the original image to be located and the file data to be saved in hidden fields. When the form is submitted, these attributes are written to the photo model:

image_file_name image_file_size image_content_type

Since writing these attributes alone doesn't seem to be enough to trigger Delayed Paperclip to process the image, Photo.save

I then call Photo.image.reprocess!

that DelayedPaperclip gets to create a new Sidekiq job that successfully processes the image.

The problem is that when I call Photo.save

in PhotosController

, the file is copied to the directory temp

from S3 and then back to S3. This happens outside the job and is blocked:

[paperclip] copying image_assets/grab-original.tiff to local file /var/folders/bv/x495g9g10m7119680c9ssqmr0000gn/T/94943834d26bcb8b471f4eeb2a7f899d20141125-3895-1oqom7l
[AWS S3 200 2.601589 0 retries] get_object(:bucket_name=>"example-com-development",:key=>"image_assets/grab-original.tiff")

[paperclip] saving image_assets/grab-original.tiff
[AWS S3 200 2.47114 0 retries] put_object(:acl=>:public_read,:bucket_name=>"example-com-development",:cache_control=>"max-age=29030400",:content_length=>534472,:content_type=>"image/tiff",:data=>Paperclip::AttachmentAdapter: grab.tiff,:key=>"image_assets/grab-original.tiff")

      

Why does Paperclip copy the file down and back?

+3


source to share


1 answer


My approach was wonky.Even if it worked it wouldn't add an attribute image_processing

to the model Photo

.

After digging into the Delayed Paperclip API, the following seemed to do the trick:

Inside PhotosController#create

:



# Ensure we are flagged as processing
@media_item.photo.prepare_enqueueing_for(:image)

if @media_item.save
   # Add Job
   @media_item.photo.enqueue_delayed_processing
end

respond_with(:admin, @galleryable, @media_item)

      

I asked for a nicer API here: https://github.com/jrgifford/delayed_paperclip/issues/116

0


source







All Articles