使用Delayed Paperclip和S3直传上传文件

3
我正在使用Delayed Paperclip和直接上传到S3。我的模型名为Photo,其附件为image
使用JavaScript从照片表单上传图像到S3。文件存储在Paperclip期望原始图像位于的位置,并将文件详细信息保存到隐藏字段中。提交表单时,这些属性被写入Photo模型:
image_file_name image_file_size image_content_type 因为仅编写这些属性似乎不足以触发Delayed Paperclip处理图像,所以在Photo.save之后,我调用Photo.image.reprocess!,这确实使Delayed Paperclip创建了一个新的Sidekiq作业,成功地处理了图像。
问题是,在PhotosController中调用Photo.save时,文件会从S3复制到临时目录,然后再返回到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")

为什么Paperclip需要将文件复制下来再上传回去?
1个回答

0

我的方法有些奇怪。即使它能够工作,也不会将image_processing属性添加到Photo模型中。

在深入研究Delayed Paperclip 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_paperclip/issues/116


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接