-
-
Notifications
You must be signed in to change notification settings - Fork 169
Write
dr.dimitru edited this page Jul 22, 2018
·
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 -
opts.userId{String} - UserId, default null -
opts.fileId{String} - id, optional - if not set - Random.id() will be used
-
-
callback{Function} - Triggered after file is written to FS. Witherror, andfileRef, wherefileRefis a new record from DB - proceedAfterUpload {Boolean} - Proceed
onAfterUploadhook (if defined) afterBufferis written to FS - Returns {Files} - Current FilesCollection instance
import fs from 'fs';
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({collectionName: 'Images'});
fs.readFile('/data/imgs/sample.png', function (error, data) {
if (error) {
throw error;
} else {
Images.write(data, {
fileName: 'sample.png',
fielId: 'abc123myId', //optional
type: 'image/png'
}, function (writeError, fileRef) {
if (writeError) {
throw writeError;
} 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 |
|
