Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send a multipart response in expressjs?

I have an app that displays a list of pictures with titles and descriptions. The app sends a get request to the node server, and I want it to respond with the pictures and the titles/descriptions. In order to send the images at the same time as the other stuff, I think I need to use the multipart/form-data Content-Type. How do I do that? The expressjs docs don't say anything about multipart responses as far as I can tell.

like image 945
EKW Avatar asked Nov 08 '22 05:11

EKW


1 Answers

In your case I would send only an initial response with image urls and then generate <img src="image.url"> in the front end.

You don't need multipart here because there will be two separate requests, one for the image metadata, and another when the browser displays the image (downloads the file).

Nevertheless I commented a use case example in which multipart responses seems to be the only way around, and currently cannot find a solution for that one, so thanks for asking.

like image 196
cancerbero Avatar answered Nov 14 '22 23:11

cancerbero