question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(Question) addFile with gridfs

See original GitHub issue

It 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:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jankapunktcommented, Apr 21, 2021

@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

1reaction
dr-dimitrucommented, Apr 21, 2021

@kakadais I’m glad we solved it quickly 🎉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found