-
-
Notifications
You must be signed in to change notification settings - Fork 167
Write
dr.dimitru edited this page Apr 8, 2016
·
6 revisions
Write Buffer
to FS and add record to Files collection. This function is asynchronous.
-
buffer
{Buffer} - File data asBuffer
-
opts
{Object} - Recommended properties:-
opts.fileName
{String} - File name with extension, likename.ext
-
opts.type
{String} - Mime-type, likeimage/png
-
opts.size
{Number} - File size in bytes, if not set file size will be calculated fromBuffer
-
opts.meta
{Object} - Object with custom meta-data
-
-
callback
{Function} - Triggered after file is written to FS. Witherror
, andfileRef
, wherefileRef
is a new record from DB - Returns {Files} - Current Meteor.Files instance
var Images = new Meteor.Files({collectionName: 'Images'});
fs.readFile('/data/imgs/sample.png', function (error, data) {
if (error) {
throw error;
} else {
Images.write(data, {
fileName: 'sample.png',
type: 'image/png'
}, function (error, fileRef) {
if (error) {
throw error;
} else {
console.log(fileRef.name + ' is successfully saved to FS. _id: ' + fileRef._id);
}
});
}
});
Meteor-Files | Support | Try ostr.io |
---|---|---|
If you found this package useful, — star it at GitHub and support our open source contributions with a monthly pledge, or submit a one-time donation via PayPal | Monitoring, Analytics, WebSec, Web-CRON and Pre-rendering for a website |