简体   繁体   English

使用Paperclip将上传文件定向到S3

[英]Using Paperclip to direct upload files to S3

so I've got paperclip set up with uploadify to upload things to S3. 所以我用uploadify设置了回形针,将内容上传到S3。 I have made my setup so that stuff gets loaded directly to S3 and then when it's done I post to my webserver the results... 我已经进行了设置,以便将内容直接加载到S3,然后在完成后我将结果发布到我的网络服务器...

All I get back is the file name and size. 我得到的只是文件名和大小。 am I supposed to build my own processor or before_post_process method to "download" the file from S3 in order to process it? 我应该构建自己的处理器或before_post_process方法从S3“下载”该文件以进行处理吗? or am I missing something and uploadify should have provided me a stream with the file inside it after it was done posting to S3? 或者我错过了什么,uploadify应该在发布到S3之后为我提供了一个包含文件的流?

How do you guys go about direct uploads to S3 and then notifying your paperclip backed model? 你们如何直接上传到S3,然后通知你的回形针支持的模型? Do you have to pull files from the server and do post-processing on them or will paperclip handle all of that? 你是否必须从服务器中提取文件并对它们进行后处理或者回形针处理所有这些?

Here are a couple blog posts describing how to do it... 这里有一些博客文章描述了如何做到这一点......

http://www.railstoolkit.com/posts/uploading-files-directly-to-amazon-s3-using-fancyupload http://www.railstoolkit.com/posts/uploading-files-directly-to-amazon-s3-using-fancyupload

http://www.railstoolkit.com/posts/fancyupload-amazon-s3-uploader-with-paperclip http://www.railstoolkit.com/posts/fancyupload-amazon-s3-uploader-with-paperclip

They use FancyUploader (which uses MooTools/Flash) to upload directly to S3, bypassing Heroku and their dreaded 30 second request timeout all together, and then use DelayedJob to queue up post-processing tasks like thumbnailing and PaperClip to do the actual processing of the files. 他们使用FancyUploader(使用MooTools / Flash)直接上传到S3,绕过Heroku及其可怕的30秒请求超时,然后使用DelayedJob排队后处理任务,如缩略图和PaperClip,以进行实际处理文件。

If I can get this working with CarrierWave, I will post up a project on GitHub to share (in a week or so once I get time) 如果我可以使用CarrierWave,我将在GitHub上发布一个项目进行分享(一旦我有时间,一周左右)

Update : 更新

Sample project using Rails 3, Flash and MooTools-based FancyUploader to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-FancyUploader 使用Rails 3,Flash和基于MooTools的FancyUploader直接上传到S3的示例项目: https//github.com/iwasrobbed/Rails3-S3-Uploader-FancyUploader

Sample project using Rails 3, Flash/Silverlight/GoogleGears/BrowserPlus and jQuery-based Plupload to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-Plupload 使用Rails 3,Flash / Silverlight / GoogleGears / BrowserPlus和基于jQuery的Plupload的示例项目直接上传到S3: https//github.com/iwasrobbed/Rails3-S3-Uploader-Plupload

I will add the post-processing example once I have time. 我有时间后会添加后处理示例。

You can either create a processor or use the callback methods but the file will definitively be on your server before going to S3. 您可以创建处理器或使用回调方法,但在转到S3之前,该文件最终将在您的服务器上。

If you are in the callback method for example you can access it using something like: 例如,如果您使用回调方法,则可以使用以下方法访问它:

self.file.to_file

Once that is done processing and uploading the file will be deleted from your server. 完成后,处理和上传文件将从您的服务器中删除。 You don't need to do anything to notify or post process. 您无需做任何事情来通知或发布流程。 Paperclip will handle it. Paperclip将处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM