0

I have developed an API in express that returns text and images separately in two different calls, but for performance reasons I would like to return the text and image (probably in a blob object) in the same response.

Now I'm doing it with the res.send() and res.sendFile() methods but I haven't been able to read anything in the documentation about how to send both at the same time. How could I do it?

Examples of what I'm doing now:

   async getImage(req, res){

   //Doing things with req

    let mypath = './foo/bar'
    let file = new Blob(path.resolve(mypath), {type: 'image/png'});
    return  res.sendFile(file)
    }

    
    async getText(req, res){

    // Doing things with req

    return res.status(200).send({ message: 'foo' })
    }
  • passing around images in JSON is not a good idea, nor will it improve performance, seems like an x y problem, also read: https://stackoverflow.com/questions/1443158/binary-data-in-json-string-something-better-than-base64#:~:text=The%20JSON%20format%20natively%20doesn,data%20is%20to%20use%20Base64. – Lawrence Cherone May 19 '22 at 22:10
  • Thanks for that information, very useful. Yes I was trying to do something I don't need. – Jose Escalada May 20 '22 at 23:13

0 Answers0