The CollectionFS package has been shelved and discontinued by it's author; however, since there's no alternative package in Atmosphere or the Meteor ecosystem for using Mongo's GridFS functionality, and the code still works perfectly fine; we recommend not removing the example from StackOverflow Documentation until some other GridFS solution can be documented as it's replacement.
However, if you're really serious about storage, and you want to store millions of images, you're going to need to leverage Mongo's GridFS infrastructure, and create yourself a storage layer. For that, you're going to need the excellent CollectionFS subsystem.
Start by adding the necessary packages.
And adding a file upload element to your object model.
Then add an event controller on the client.
And define your collections on your server:
Thanks to Raz for this excellent example. You'll want to check out the complete CollectionFS Documentation for more details on what all CollectionFS can do.
Dropzone (with iron:router)
If we want something a bit more polished, with an integrated Dropzone UI and a REST endpoint, we're going to need to start adding custom REST routes and packages with UI helpers.
Lets begin by importing Iron Router and Dropzone.
And configure the uploads url route that's specified in the dropzone helper.
Cool! We have a file uploader with snazzy UI and a programmable REST endpoint. Unfortunately, this doesn't scale particularly well.
To scale things, we have to stop using local storage on our server, and start using either a dedicated file storage service or implement a horizontal storage layer. The easiest way to get started with scalable file storage is to use a solution like Filepicker.io, which supports S3, Azure, Rackspace, and Dropbox. loadpicker has been a popular Filerpicker unipackage for awhile.
The Filepicker pattern is rather different than the other solutions, because it's really about 3rd party integration. Begin by adding a filepicker input, which you'll see relies heavily on data-* attributes, which is a fairly uncommon pattern in Meteor apps.
You'll walso want to set an API key, construct the filepicker widget, trigger it, and observe it's outputs.
The following scripts are for uploading a file from the server filesystem into the server. Mostly for config files and filewatchers.
Uploading files can be easy or really complicated, depending on what you're wanting to do. In general, transfering a file itself isn't all that difficult. But there are lots of edge cases around attachments, binary files, and the like. And the real sticking point is horizontal scaling, and creating a solution that works when the server is cloned a second, third, and nth time.
Let's start with a basic server/client upload model. We begin by adding a file input element to the document object model.
Then attach an event to the input element within your controller, and call a local Meteor method ``startFileTransfer'' to initiate the transfer.
The client will then call the saveFileToDisk server method, which does the actual transfer and puts everything to disk.
That's sort of the bare-bones approach, and it leaves a lot to be desired. It's maybe good for uploading a CSV file or something, but that's about it.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0