Storing data stream from POST request in GridFS, express, mongoDB, node.js

后端 未结 5 1728
予麋鹿
予麋鹿 2020-12-01 05:53

I am trying to figure out how I can post an image directly to GridFS without storing it anywhere on the server as a temporary file first.

I am using Postman (chrome

5条回答
  •  情书的邮戳
    2020-12-01 06:20

    gridfs-stream makes that pretty easy:

    // `gfs` is a gridfs-stream instance
    app.post('/picture', function(req, res) {
      req.pipe(gfs.createWriteStream({
        filename: 'test'
      }));
      res.send("Success!");
    });
    

提交回复
热议问题