Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
How can I create read stream from a post request in node js

I am trying to upload a file containing text, images, and video, so I am using grid fs stream to upload it but 'fs' only reads files from the 'file system', but the file is submitted from an HTML text editor to the post request. Is there any way I can create a read stream from the post request?

app.post('/blogs', urlencodedParser, (req, res) => {
    mongodb.MongoClient.connect(uri, function (error, client) {
        assert.ifError(error);

        const db = client.db(dbName);

        var bucket = new mongodb.GridFSBucket(db);

        fs.createReadStream(req.body.title, req.body.desc, req.body.virtual_content).
            pipe(bucket.openUploadStream(req.body.title, req.body.desc, req.body.virtual_content)).
            on('error', function (error) {
                assert.ifError(error);
            }).
            on('finish', function () {
                console.log('done!');
                process.exit(0);
            });
    });

    mongodb.MongoClient.connect(uri, function (error, client) {
        assert.ifError(error);

        const db = client.db(dbName);

        var bucket = new mongodb.GridFSBucket(db);

        // Use bucket...
    });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!