Question

I could simply create chunks of a file and then write those "manually" using mongo inserts, but as far as I understand GridFS will take care of the chunking. If someone could shed some light on the nodejs API implementation of GridFS in MongoDB it would be appreciated. Also that others looking for a solution can have a resource here :)

I need a sample code which can upload images into gridfs using nodejs.

Was it helpful?

Solution

If you want to use GridFS, you indeed should use APIs that provide the same level of abstraction. As you said yourself, you probably could use mongo queries directly, but would end up writing your own implementation of a GridFS library.

I'd probably start with GridStore, which is part of Mongo's native node.js driver. Last year, there was very a good primer for GirdFS on on node.js knockout, which you could check out for some practical examples.

What you roughly need to do is:

  • Connect to your mongo database
  • Get an instance of Grid class with active db connection as a parameter
  • Use the GridFS via Grid instance
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top