Upload Media Using Meteor-Files
Explore how to use the Meteor-Files package to upload media files in Meteor.js applications. Learn to configure file restrictions, handle upload progress, and store files efficiently on the server or third-party services. Understand how to publish and subscribe to uploaded media within a React frontend.
We'll cover the following...
Meteor-Files
Meteor-Files is a third-party Meteor package that’s very efficient at uploading files for storage. It can store files on the server’s file system and in third-party storage like Amazon S3, Dropbox, GridFS, and so on. It’s compatible with most front-end frameworks used by Meteor. It supports resumable downloads and also provides functional hooks, which we can utilize to perform custom logic as a file is uploaded. Hooks such as onAfterUpload and onBeforeUpload can be used to perform custom logic on uploaded files.
Meteor-Files is installed on our project by running the following command on the terminal:
meteor add ostrio:files
Meteor-Files saves the path of the uploaded file in MongoDB. We can retrieve uploaded files using the same Meteor MongoDB API as find to pull documents out of collections.
The playground below demonstrates how to upload files using Meteor-Files.
Meteor-Files configuration
Open the imports/api/files.js file. On line 2, we import FilesCollection from the meteor/ostrio:files package. We ...