** This project in Beta **
Example
Configure Meteor Mongo Collection
1const Movies = new Mongo.Collection('movies'); 2Movies.attachBehaviour('files', { 3 field: 'image', 4 dir: '/../files/movies', 5 url: '/files/movies', 6 stores: 7 xs: [320, 180] 8 sm: [640, 360] 9});
Options
- field - The field of the document in which the file will be stored
- dir - Path to the directory for storing files (if it starts with "/" - that way will be considered relative to the project directory. It is recommended to store files outside the meteor-project, as in the example above)
- url - Url, which will be automatically generated for files. Meteor will link this url to the file directory. You can specify a url with '//' - for example, if you want to distribute files using Nginx
- stores - Storage for files. The original file will be saved in 'stores.original'. By specifying Other stores - you can pass a function - what to do with the files before saving or the array [width, height] - for images resize
Save document with file
1function save(e) { 2 // get file source 3 file = e.targer.files[0] 4 // save new document width file 5 Movies.insert({ 6 name: 'My awesome movie' 7 image: file 8 }, function(err, res) { 9 // error if mongo error or files error 10 if(err != null) { 11 console.log(err); 12 } 13 }) 14} 15
Get document with files
1let movie = Movies.findOne(); 2console.log(movie); 3// result: 4// movie = { 5// name: 'My awesome movie' 6// image: { 7// original: '/files/movies/1d22f89sd98/original.jpg', 8// xs: '/files/movies/1d22f89sd98/xs.jpg', 9// sm: '/files/movies/1d22f89sd98/sm.jpg' 10// } 11// } 12//
Features & Roadmap
- Easy configure mongo collection
- Create url for files by meteor WebApp
- Support image (jpeg/png)
- Easy resize image files
- User function for edit file after upload
- Validation files
- Multiple files to one mongo document
- Other fiches))
LICENCE ISC - Created @mrMasly