(Question) addFile with gridfs
See original GitHub issueIt seems that addFile API is not firing onAfterUpload callback so that the files are served on the location on the server. So I simulated after use it to maintain a file at the same collection.
Is there a better way to accomplish this?
DB_CSV_FILES.addFileSync = Meteor.wrapAsync DB_CSV_FILES.addFile, DB_CSV_FILES
_file = DB_CSV_FILES.addFileSync('/Users/kakadais/xmrig.sh')
Object.keys(_file.versions).forEach (versionName) ->
metadata = {versionName, fileId: _file._id, createdAt: new Date()};
writeStream = gfs.createWriteStream({filename: _file.name, metadata});
fs.createReadStream(_file.versions[versionName].path).pipe(writeStream);
writeStream.on 'close', Meteor.bindEnvironment (file) ->
property = "versions.#{versionName}.meta.gridFsFileId"
DB_CSV_FILES.update(_file._id, {$set: {"#{property}": file._id.toString()}})
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
How use GridFSInputFile and GridFS without add file in ...
I think the only thing you are missing here is an "empty" input stream where there is no file attachment. This is fairly...
Read more >GridFS — MongoDB Manual
GridFS uses two collections to store files. One collection stores the file chunks, and the other stores file metadata. The section GridFS Collections...
Read more >Uploading Files to MongoDB with GridFS and Multer Using ...
Hello, in this tutorial we will learn how to upload files directly to MongoDB using GridFS specification.
Read more >com.mongodb.gridfs.GridFSInputFile.save java code examples
Reads a buffer full from the java.io.InputStream. createChunk. Creates a new chunk of this file. Can be over-ridden, if input files need to...
Read more >How can I use GridFS to load a file on the server after I create ...
I do have code to load files client side using GridFS but I am having a hard time changing the code to work...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@kakadais just a follow-up message here: gridfs-stream is deprecated, you should use Mongo-Internal gridFS buckets.
The wiki covers this topic: https://github.com/veliovgroup/Meteor-Files/wiki/GridFS-Bucket-Integration There is an example repo, too: https://github.com/veliovgroup/files-gridfs-autoform-example
I finally wrote a factory that creates FilesCollections with out-of-the-box gridFS bucket integration (will be updated the next days to work with zero-config): https://github.com/leaonline/grid-factory
@kakadais I’m glad we solved it quickly 🎉