mongodb gridfs carrierwave or joint or other? - ruby-on-rails

i want to store all my assets in mongo gridfs. i was trying to get
carrierwave setup with mongomapper and gridfs but seems carrierwave
supports mongoid now instead.
I need to be able to save different size versions / cropped versions
of an image so thats why i was going to use carrierwave. Currently
its set up to store on file system using paperclip but paperclip is
not easy or i have not found a good way to store in gridfs. ??
Should i be using joint to store assts ? but then how do i create
versions etc ?
I basically have muliple models that can have many assets. My models
are mongomapper documents / embedded docs, so i could use mongoid for
my assets model and use carrierwave ....?
please can any one help with the best solution to this ? and
hopefully point me to good examples!
thanks alot
rick

I recommend joint and just storing originals. From there, you can create alternate versions on the fly. I have used http://github.com/quirkey/imanip on projects to create alternate sizes. On the first request I typically cache the original to the file system for speedier requests and then create/cache the requested version/size.

I recommend carrierwave, because if you decide, for whatever reason, to change file stores (for example, if you want to move to a filesystem-based store instead), it will be much easier with carrierwave.
There is a carrierwave plugin called mm-carrierwave that lets you use carrierwave with MongoMapper.

Related

Best way to store many image frames in ActiveRecord with CarrierWave

I'm using Ruby On Rails 4 + ActiveRecord + CarrierWave to store images.
Now I have task - to store many image frames in each AR record for SpriteSpin 360 views. I have trouble with traditional way to store images - SpriteSpin requires up to 34 image frames. I think it isn't best way to create 34 or more attributes, and upload each frame separately.
Maybe there is more correct way to upload and store it?
I think CarrierWave doesn't support multiple uploads. It's designed to associate a single file with a single field.
If you want multiple uploads, you need either multiple fields (each with a CarrierWave uploader), or multiple objects each with a single CarrierWave uploader field.
The multiple attribute is also unsupported, so if you use it, it's entirely up to you to get the parameters assigned properly.
Here are some references of multiple uploads via Carrierwave. I am not sure you like these tricks or not? But for your reference I found..
Multiple file upload with carrierwave, nested form and jquery file upload
Multiple file uploads with Ajax, Carrierwave, & Mongoid
Stack Overflow's Answer
I hope this helps you somehow... Or wait for someone's answer who had done this before. I am big fan of and love to use Paperclip

Is there a gem for ruby on rails that let's a user upload an image for a model?

I am working on a little app and I am curious if there is a way for a user to use the generated scaffolding to both (1) assign an image file name to a field, and (2) to automatically upload that file to the server when successful.
The idea is to create a simpler editorial process. My understanding is that including a blob in the table would not be good coding standards, so... if I can't store it in the database directly, then we need to store the image file name. But at the same time we need to ensure that that image is truly available on the server. In which case I'd like to cover both cases at the same time - allowing the editor to do their job.
is there an existing gem that I can leverage? Thanks
I'm not quite sure about your use case, and it seems like that's important, something about adding an image in a text editing field?
To answer one question, no, you can't do it with the default Rails scoffolding, although RailsAdmin and ActiveAdmin have paperclip support (and yes, to second #emaillenin, paperclip is probably the most common option).
Also check out JQuery File Upload for my favorite "scaffolding"-esque file uploader; although it's more work than say RailsAdmin, it's a great experience because you get thumbnail previews while the upload is going and progress bars all for free.
If it helps, I have a photo gallery project stored on Github, not "open source" in the sense that I attempted to make it useful to others, but I don't care if people browse it. It uses jquery-file-upload. Useful files:
Gemfile has:
gem 'paperclip'
gem 'jquery-fileupload-rails'
Then the photo model, categories controller for uploading photos as a nested resource, and the file-upload template translated to HAML.
How about Paperclip gem? - It lets you upload images, assign filename to a column in your model, validations on your attachments and helper functions to display them in your views.
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.
Some alternatives - CarrierWave and more.

What is the simplest Rails file upload method?

I've looked at the available options and it seems like everything is optimized for image uploading as display. I just need simple file upload and retrieval. Are there any good options?
Paperclip is a popular choice for uploading and sizing images, but you can upload any type of file with it (doc, zip, txt, pdf... anything). Highly recommended. https://github.com/thoughtbot/paperclip
I like carrierwave. It has built in support for s3, has no workaround for setting up apps on heeroku unlike paperclip.
I use Carrierwave for mine and have been happy with it. I am just uploading general files, not specifically images. It is easy to implement and has good advanced features if you need them later. It also integrates with Fog to make using remote storage sources (like s3 or rackspace cloud files) easy.
Carrierwave benefits:
With carrierwave, the attachment is a seperate model instead of an attribute on an existing model, which might make things cleaner to work with.
It comes with the ability to attach a file via url (user passes in a url to a file) instead of uploading with a form).
It comes with some sort of way to remember files across form validation failures, although I've never used this and I'm not sure how it's done... maybe with two forms and ajax?
It seems to have a more engaged and enthusiastic community around it, with more projects extending it.
For S3, they use fog instead of aws-s3, and fog has much more active development.
That said, paperclip is pretty great and is actively maintained, and might come with handier default image manipulation stuff, I'm not sure.

How do I add file uploads to a rails app?

I need to add the ability to upload and store any kind of file, PDF, XLS, DOC, etc. What is the best way to do this in a ruby on rails application?
I think this is exactly what you're looking for.
Upload files.
I'd recommend you to use paperclip or carrierwave both are really good libs and work out of the box in most cases.
you can also look at attachment_fu rails.
I've worked with two of the big players when it comes to file uploads. carrierwave and paperclip.
They provide a good solution for a common task with support for different storage alternatives. Both support filesystem and S3. Carrierwave also supports Rackspace Cloud Files and MongoDB’s GridFS.
I would recommend carrierwave because of one aspect where they are different to use. It uses a separate upload class that you mount on your model. This separates your code related to the file upload from the model code. I find this approach cleaner and easier to test.

Storing documents using Ruby On Rails

I would like users of my ruby on rails app to be able to upload documents (Word Documents, Spreadsheets, PDFs, etc). What is the best way of doing this?
I've used file_column, attachment_fu, and paperclip. I've also had to dive into the source on all three plugins.
Without a doubt, I recommend paperclip above the others. The source is easier to read and understand. Its easier to extend. It doesn't do extraneous file copies.
Go with paperclip and let us know if you have any questions.
"Best" depends on your exact needs, but have a look at PaperClip. It's a pretty easy way to integrate files with ActiveRecord.
I agree that Paperclip is the best solution currently available.
If you decide to use Paperclip, you might want to take a look at this question which discusses how to display thumbnails for non-image types (.doc, .xls etc).
Set path for original images using paperclip in Rails?

Resources