载波或蜻蜓
我一直在研究 Rails 文件上传工具,对我来说最有吸引力和最有趣的是 Carrierwave 和 Dragonfly。
从环顾四周来看,Carrierwave 似乎采用了更传统的风格,您可以在保存时处理文件,而 Dragonfly 是中间件,因此它允许您即时处理。
我想知道人们是否有任何关于性能测试或比较两者的测试的参考。
另外,只是想知道人们对两者的看法是什么,他们更喜欢哪一个,当然还有他们为什么喜欢它。
I have been looking into rails file upload tools and the ones that seemed the most appealing and interesting to me were carrierwave and dragonfly.
From looking around it seems like carrierwave takes the more traditional style where you can process the file on save whereas dragonfly is middleware so it allows you to process on the fly.
I was wondering if people had any references to performance test or any test that compare the two.
Also, just curious on what people's opinions are about both and which they prefer and of course why they prefer it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
取决于设置。正如 Senthil 所写,只要前面有一个缓存代理,就可以使用 Dragonfly。
但如果您使用内置的 Rails 缓存,Carrierwave 的性能会更好,因为文件无需任何处理即可加载。如果你不做任何处理,那就没关系。
以下是我在使用 Mongomapper 的项目中考虑图像时的总结:
Carrierwave:
蜻蜓:
我最终使用了两者。
未来的愿望是 Carrierwave 能够再次支持 MongoMapper。在各种情况下使用两者之后,我发现 MongoMapper(rails3 分支)中的功能始终有效,并且很容易使用插件进行扩展。目前还不能对 Mongoid 说同样的话,但这可能会改变。
Depending on the setup. As Senthil writes, as long as you have a cache-proxy in front, it's fine with Dragonfly.
But if you are using the built-in rails caching, Carrierwave will perform better, as the files can be loaded without any processing. If you don't do any processing, it doesn't matter.
Here's how I summarized when considering both for Images on a project with Mongomapper:
Carrierwave:
Dragonfly:
I ended up using both in the end.
A future wish is for carrierwave to suppert MongoMapper again. After using both in various situations, I've found that the features in MongoMapper (rails3 branch) always works, and are easy to extend using plugins. Cannot say the same for Mongoid as of now, but that might change.
我使用 Dragonfly 只是因为 Carrierwave 放弃了对 mongomapper 的支持,而回形针在没有一些 hack 的情况下无法使用 mongomapper。
蜻蜓进行即时处理,即
I use dragonfly simply because carrierwave dropped support for mongomapper and paperclip doesn't work mongomapper without some hacks.
Dragonfly does processing on the fly, i.e.
Paperclip
Paperclip 旨在作为 Active Record 的简单文件附件库。其背后的目的是使设置尽可能简单,并尽可能像对待其他属性一样对待文件。这意味着它们不会保存到磁盘上的最终位置,如果设置为 nil,它们也不会被删除,直到调用
ActiveRecord::Base#save
为止。如果需要,它会根据大小和存在来管理验证。如果需要,它可以将指定的图像转换为缩略图,并且先决条件就像安装 ImageMagick 一样简单(对于大多数现代基于 Unix 的系统来说,就像安装正确的软件包一样简单)。附加文件保存到文件系统中,并通过易于理解的规范在浏览器中引用,该规范具有合理且有用的默认值。优点
附件内容类型验证器
附件存在验证器
AttachmentSizeValidator
将属性设置为 nil 并保存。
@user.avatar = nil @user.save
CarrierWave
这个 gem 提供了一种简单且极其灵活的方法来从 Ruby 应用程序上传文件。它与基于 Rack 的 Web 应用程序配合良好,例如 Ruby on Rails。
优点
image
属性来引用上传的图像。事实之一是它不会使您的模型配置混乱。您可以改为定义上传器类。它允许您轻松地重用、扩展等您的上传配置。
我们最喜欢的是 CarrierWave 非常模块化。您可以轻松地在本地文件系统、基于云的 AWS S3 等之间切换存储引擎。您可以在 RMagick、MiniMagick 和其他工具之间切换图像处理模块。您还可以在开发环境中使用本地文件系统,并在生产系统中切换到 S3 存储。 Carrierwave 对外部事物(如 DataMapper、Mongoid、Sequel)有很好的支持,甚至可以与第 3 方图像管理(如 cloudinary)一起使用该解决方案似乎是最完整的,对任何事物的支持范围都很完整,但该解决方案也更加混乱(对我来说)至少)因为您需要处理更多代码。需要了解 CarrierWave 采用的模块化方法。它不知道您使用哪种流行的 S3 客户端,支持 aws/s3 和 right_aws。它还与 ORM 无关,并且与 Active Record 不紧密耦合。 Paperclip 的紧密耦合给我们的工作带来了一些痛苦。
缺点
Dragonfly
image_tag @product.image.thumb('150x150#')
成为可能。优点
是的:蜻蜓
否:Carrierwave 或 Paperclip
)
Paperclip
Paperclip is intended as an easy file attachment library for Active Record. The intent behind it was to keep setup as easy as possible and to treat files as much like other attributes as possible. This means they aren't saved to their final locations on disk, nor are they deleted if set to nil, until
ActiveRecord::Base#save
is called. It manages validations based on size and presence, if required. It can transform its assigned image into thumbnails if needed, and the prerequisites are as simple as installing ImageMagick (which, for most modern Unix-based systems, is as easy as installing the right packages). Attached files are saved to the filesystem and referenced in the browser by an easily understandable specification, which has sensible and useful defaults.Advantages
AttachmentContentTypeValidator
AttachmentPresenceValidator
AttachmentSizeValidator
Set the attribute to nil and save.
@user.avatar = nil @user.save
CarrierWave
This gem provides a simple and extremely flexible way to upload files from Ruby applications. It works well with Rack based web applications, such as Ruby on Rails.
Advantages
image
attribute for referencing the uploaded image.One of the fact that it doesn't clutter your models with configuration. You can define uploader classes instead. It allows you to easily reuse, extend etc your upload configuration.
What we liked most is the fact the CarrierWave is very modular. You can easily switch your storage engine between a local file system, Cloud-based AWS S3, and more. You can switch the image processing module between RMagick, MiniMagick and other tools. You can also use local file system in your dev env and switch to S3 storage in the production system. Carrierwave has good support for exterior things such as DataMapper, Mongoid, Sequel and even can be used with a 3rd party image managment such as cloudinary The solution seems most complete with support coverage for about anything, but the solution is also much messier (for me at least) since there is a lot more code that you need to handle. Need to appreciate the modular approach that CarrierWave takes. It’s agnostic as to which of the popular S3 clients you use, supporting both aws/s3 and right_aws. It’s also ORM agnostic and not tightly coupled to Active Record. The tight coupling of Paperclip has caused us some grief at work.
Disadvantages
Dragonfly
image_tag @product.image.thumb('150x150#')
possible.Advantages
Yes: Dragonfly
No: either Carrierwave or Paperclip
Disadvantages
rack::cache
or similar.References
其他人写了很好的总结,我只是想说,根据我们的经验,Dragonfly 设置需要更多维护,并且由于一些开发人员的疏忽,我们还陷入了许多孤立图像,这些图像在原始图像之后仍然存在被删除。使用普通载波就不会发生这种情况。
PS 我们迁移到了 cloudinary(并使用了它的 Carrierwave)并且对此感到满意。
Other people wrote pretty good summaries, I just would like to say that from our experience Dragonfly setup needed more maintenance, and because of negligence of some developer(s) along the way we were also stuck with plenty of orphan images which lingered after the original was removed. This wouldn't have happened with a vanilla carrierwave.
P.S. We migrated to cloudinary (and use carrierwave with it) and are happy with it.