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.
-
You should read this before you attempt it: stackoverflow.com/questions/1806228/…Pop-A-Stash– Pop-A-Stash2016-11-25 19:33:22 +00:00Commented Nov 25, 2016 at 19:33
-
@JoelCDoyle It's a swift app. I plan on writing my own script to decode it into meaningful data.EKW– EKW2016-11-25 20:03:44 +00:00Commented Nov 25, 2016 at 20:03
-
try multer npm. this will save your timevijay– vijay2016-11-25 20:04:05 +00:00Commented Nov 25, 2016 at 20:04
-
2@vijay I thought multer only parsed multipart data being sent to the server. I need to send multipart data from the server.EKW– EKW2016-11-25 21:28:17 +00:00Commented Nov 25, 2016 at 21:28
-
1this is a great question. In my case the use case is users exporting some data to excel and besides downloading the file they need to see some logs/reports. This is a heavyweight processing task that generates both things together. I think a multipart response is the answer in this scenario, because the files are too large to be decoded as base64 json properties client side. Another "hack" would be sending the json as a response header (puaj)...cancerbero– cancerbero2021-01-27 01:47:54 +00:00Commented Jan 27, 2021 at 1:47
|
Show 2 more comments
1 Answer
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.