How should I handle file uploads in Meteor?

I want users to be able to download files like images, PDFs, Word documents, audio files, etc. I want to know if I should store all the files on the server locally or use an external hosting file where I can access the files using the API.

If I have to save locally, how do I do it in MeteorJS? What packages or methods would you recommend for this?

+3


source to share


2 answers


Using a third party service like Amazon (S3 or Cloud Front) is best because it will reduce the load on your application. Such a package will help in this process: https://atmospherejs.com/edgee/slingshot .



+5


source


Storing files on your server locally, you may have to store them in a special folder and serve its contents with Apache or Nginx, however I don't think this is a good idea because you are going to waste your application server resources for a task that is much better performed by external storage services (Google Cloud Storage, Amazon S3, etc.).

You can even store files in MongoDB, but that's even worse because they won't be easily cacheable and somewhat inefficient and inaccessible.

The most elegant way is probably uploading your files directly from the end-user client to external storage servers, without even going through the Meteor app server. The client will only send the URL of the saved files to your Meteor server to store them in MongoDB. External storage has the ability to offer cheap Gb / month prices and provide high scheduling, replication across multiple servers, etc.



There is a Meteor package that implements this workflow, I have not personally tested it, but I am sure it is reliable material and I will try it out.

https://github.com/CulturalMe/meteor-slingshot

The configuration can be a little tricky to get the first time around, but that's definitely the way to go.

+7


source







All Articles