As far as I know, in nodeJS (though you didn't specifically mentioned it in your question, just tagged it), the GridStore
object is to be used for manipulating the files:
(quoted form the GridStore doc)
Opening a GridStore (a single file in GridFS) is a bit similar to opening a database. At first you need to create a GridStore object and then open it.
var gs = new mongodb.GridStore(db, filename, mode[, options])
Reading from GridStore can be done with read
gs.read([size], callback)
where
- size is the length of the data to be read
- callback is a callback function with two parameters - error object (if an error occured) and data (binary string)
Streaming from GridStore:
You can stream data as it comes from the database using stream
gs.stream([autoclose=false])
where
- autoclose If true, current GridStore will be closed when EOF and ‘close’ event will be fired
The function returns read stream based on this GridStore file. It supports the events ‘read’, ‘error’, ‘close’ and ‘end’
.
Also, at the quoted doc site, there are a lot of useful examples for storing file, etc...
Recommended reading: