3

我在直接上传到 S3 的同时使用延迟回形针。我的模型被称为Photo,它的附件是image

使用 JavaScript 从照片表单将图像上传到 S3。该文件存储在 Paperclip 期望原始图像所在的位置,并且文件详细信息保存到隐藏字段中。提交表单时,这些属性将写入 Photo 模型:

image_file_name image_file_size image_content_type

因为单独编写这些属性似乎不足以触发 Delayed Paperclip 来处理图像,所以在Photo.save我调用Photo.image.reprocess!which 确实得到 DelayedPaperclip 以创建一个成功处理图像的新 Sidekiq 作业之后。

问题是,当我调用Photo.savePhotosController,文件会从 S3 复制到temp目录,然后再复制回 S3。这发生在工作之外并且阻塞:

[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")

为什么回形针将文件上下复制?

4

1 回答 1

0

我的方法很不稳定。即使它起作用了,它也不会将image_processing属性添加到Photo模型中。

在深入研究了延迟回形针 API 之后,以下内容似乎成功了:

内部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)

我在这里请求了一个更好的 API:https ://github.com/jrgifford/delayed_pa​​perclip/issues/116

于 2014-11-25T22:09:38.107 回答