0

We're using Paperclip to upload files to S3 by presenting a browse dialog to the user. That's works nice & smooth. However, now I wish that some background job will do some crawling, and when it reaches a required file, upload that one as well. Obviously I can't use the browse dialog at this point.

All examples I saw for using Paperclip is about selecting the file manually from the client (by updating the view). I've failed to find how to set up the file to be uploaded by code, and since the UI component triggers some "behind the scenes" work that creates some object with additional information that I couldn't find how to use or call.

Any ideas? Thank you

4

1 回答 1

0

您可以在不使用浏览对话框的情况下创建回形针上传,也不需要用户操作。Paperclip 需要一个文件,只需生成一个 tmp 文件或使用存储中的现有文件。

你的回形针模型类:

class YourPaperclipmodel < ActiveRecord::Base
  has_attached_file :data
end

生成文件:

YourPaperclipmodel.create(:data => File.open("path to existing file or tmp generated file"))
于 2013-05-05T22:36:08.300 回答