Add local file to FilesCollection from FS.
Note: You can not use this method on public
collections. As they supposed to be served without NodeJS (Meteor) participation. But you always can move file to root of your web-server and then add a record to FilesCollection.
path
{String} - Full path to file, like/var/www/files/sample.png
opts
{Object} - Recommended properties:opts.fileName
{String} - File name with extension, likename.ext
opts.meta
{Object} - Object with custom meta-dataopts.type
{String} - Mime-type, likeimage/png
opts.size
{Number} - File size in bytes, if not set - size will be calculated from fileopts.userId
{String} - UserId, default nullopts.fileId
{String} - _id of inserted file, if not set - Random.id() will be used
callback
{Function} - Triggered after new record is added to Collection. Witherror
, andfileRef
, wherefileRef
is a new record from DBproceedAfterUpload
{Boolean} - ProceedonAfterUpload
hook (if defined) after local file is added toFilesCollection
- Returns {FilesCollection} - Current FilesCollection instance
import { FilesCollection } from 'meteor/ostrio:files';
const imagesCollection = new FilesCollection({collectionName: 'images'});
imagesCollection.addFile('/var/www/files/sample.png', {
fileName: 'sample.png',
type: 'image/png',
fileId: 'abc123AwesomeId',
meta: {}
});