Paperclip 用于将图像上传到 Rails 中的 S3。文件上传速度非常慢。解决方法?
我正在开发一个 Rails 应用程序,用户将在其中上传大量图像。
我当前的设置:使用带有 S3 存储的 Paperclip 插件使用 SWFUpload 一次上传多个文件。原始图像上传到S3后,Delayed_Job用于后期处理(缩略图等)。
我遇到的问题是图像上传速度非常慢。我假设默认的回形针设置是图像将从用户转到 ->我的服务器到-> s3。
我想我可以将图像直接上传到 s3,但我不确定如何使用 Paperclip 和后期处理来实现这一点。我找不到任何涉及此问题的插件或示例。
有人有建议吗?如果没有,你能指出我正确的方向吗?
提前致谢!
蒂姆
I'm working on a rails app where the user will be uploading large quantities of images.
My current setup: Using SWFUpload to upload multiple files at once using the Paperclip plugin with S3 storage. After the original image is uploaded to S3, Delayed_Job is used for the post processing (thumbnails, etc).
The problem I have is that the images upload at a very slow rate. I'm assuming the default Paperclip setup is that the image will go from the user to -> my server to -> s3.
I was thinking that I can have the images upload directly to s3 but I'm not sure how to implement that with Paperclip and post processing. I couldn't find any plugins or examples dealing with this.
Does anyone have suggestions? If not, can you point me in the right direction?
Thanks in advance!
Tim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经遇到过同样的问题好几次了。我解决这个问题的方法是创建 2 个模型,一个
Image
模型和一个TempImage
模型,它继承自Image
模型。这要求您的Image
表上有一个type
列。TempImage
模型将图像保存在本地,然后当您直接从Image
模型访问它并重新保存它时,它将遵循Image
中定义的内容代码>模型,是Amazon S3。示例:
这是我延迟的工作:
这是
TempImage
模型:然后是原始
Image
模型:您的原始
Image
模型应始终包含您的帖子处理,因为这将在后台完成。您始终可以覆盖一些方法以使其更简洁,但这可以让您更好地了解它是如何工作的以及您需要做什么,以便您可以让它像您希望的那样工作。
I've ran into this same problem a few times. The way I solved it was by creating 2 models, a
Image
model and aTempImage
model, which inherits from theImage
model. This requires you to have atype
column on yourImage
table. TheTempImage
model saves the image locally, then when you access it from theImage
model directly and resave it, it will follow whatever is defined in theImage
model, being Amazon S3.Example:
Here is my delayed job:
Here is the
TempImage
model:Then the original
Image
model:Your original
Image
model should always contain your post processing, as that will be done in the background.You can always overwrite some methods to make it a little cleaner, but this gives you a better idea of how it works and what you need to do to so you can have it work like you want it to.
如果您最终选择直接上传到 S3,这会减轻 Rails 服务器上的工作负担,请查看我的示例项目:
使用 Rails 3、Flash 和基于 MooTools 的 FancyUploader 直接上传到 S3 的示例项目:https://github.com/iwasrobbed/Rails3-S3-Uploader-FancyUploader
使用 Rails 的示例项目3、Flash/Silverlight/GoogleGears/BrowserPlus和基于jQuery的Plupload直接上传到S3:https ://github.com/iwasrobbed/Rails3-S3-Uploader-Plupload
顺便说一句,您可以使用 Paperclip 进行后期处理,使用如下博客文章所述:
http://www.railstoolkit.com/posts/fancyupload-amazon-s3-uploader-with-paperclip
If you end up going the route of uploading directly to S3 which offloads the work from your Rails server, please check out my sample projects:
Sample project using Rails 3, Flash and MooTools-based FancyUploader to upload directly to 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
By the way, you can do post-processing with Paperclip using something like this blog post describes:
http://www.railstoolkit.com/posts/fancyupload-amazon-s3-uploader-with-paperclip