• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

122
Views
How to pass the response in stream in GET method

Hi I am trying to pass the below data in stream form as the normal response is taking too long because of conversion of images into base64data

Looking at various similar issues I tried changing the response to pipe() but still facing issues

Please see below code for reference

Hence can you please tell me how to pass the response in stream form and check it in postman

router.js

router.get("/users/data/expand/:nid", async (req, res) => {
  var idselected = req.params.nid;
  var dir = "images";
  try {
    const checkData = await user.findOne({ user_id: idselected });

    let receivedFile = await Promise.all(
      checkData.attachments.flatMap(async element => {
        let files = await readDirectory(dir);
        return await Promise.all(
          files.map(filename => {
            filename = element;
            return readFile(filename)
          })
        );
      })
    );
    const returnUser = new User({
      user_id: checkData.user_id,
      attachments: receivedFile
    });
    let savedUser = await returnUser.save();
    res.status(201).pipe(savedUser); 
  } catch (e) {
    res.status(500).send(e);
  }
});
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error