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.

Create native GridFS integration (or document recipes)

See original GitHub issue

How can we specify the GridFS collection name (not the FilesCollection collectionName)? It defaults to fs. and I cant get it to accept new name.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
macrozonecommented, Mar 1, 2019

a small improvement over @hluz ’ suggestion above:

// interceptDownload
 .on('error', err => { throw err; })

this is bad, because if it can’t read the file, this will crash the server. Better handle it:

interceptDownload(http, file, versionName) {
      const { gridFsFileId } = file.versions[versionName].meta || {};
      if (gridFsFileId) {
        const readStream = gridFSBucket.openDownloadStream(new ObjID(gridFsFileId));
        readStream.on('data', (data) => {
          http.response.write(data);
        });

        readStream.on('end', () => {
          http.response.end('end');

        });
        readStream.on('error', () => {
          // not found probably
          // eslint-disable-next-line no-param-reassign
          http.response.statusCode = 404;
          http.response.end('not found');
        });
        http.response.setHeader('Cache-Control', this.cacheControl);
        http.response.setHeader('Content-Disposition', `inline; filename="${file.name}"`);
      }
      return Boolean(gridFsFileId); // Serve file from either GridFS or FS if it wasn't uploaded yet
    },

EDIT: i forget to set the cache control!

2reactions
dr-dimitrucommented, May 30, 2018

@hluz no worries.

Actually we wish to fork gridfs-stream and keep it in up-to-date shape 😃 . We all were sad to discover it in a such badly maintained state. Or maybe @aheckmann could give us a push rights to repository, or better transfer it to us (including NPM)? @aheckmann if you’re reading this, take a look at our experience, for years we keep many packages in up-to-date state, taking care of every ticket and PR. Consider giving your child into good hands 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create native GridFS integration (or document recipes) #616
Hello @hluz , The name of the collections in GridFS is out of our control, as it hard-coded in MongoDB's specs.
Read more >
GridFS — Node.js - MongoDB
In this guide, you can learn how to store and retrieve large files in MongoDB using GridFS. GridFS is a specification that describes...
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 >
A primer for GridFS using the Mongo DB driver
Let's dive straight into a simple example on how to write a file to the grid using the simplified Grid class. var MongoClient...
Read more >
Vmc - River Thames Conditions
Paper forms, Red bowtie mud flaps, Geiranger valldal ferry timetable, ... Fly insect types, Lucarelli restaurant italy, Garlic sauce recipe pasta, ...
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