5

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.

EKW
  • 2,059
  • 14
  • 24
  • You should read this before you attempt it: http://stackoverflow.com/questions/1806228/browser-support-of-multipart-responses – Pop-A-Stash Nov 25 '16 at 19:33
  • @JoelCDoyle It's a swift app. I plan on writing my own script to decode it into meaningful data. – EKW Nov 25 '16 at 20:03
  • try multer npm. this will save your time – vijay Nov 25 '16 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 Nov 25 '16 at 21:28
  • @EKW any updates? – omid.n Jan 11 '19 at 13:45
  • This was a while ago. I think I might have created a system to manually write the multipart request but I don't really remember. – EKW Jan 24 '19 at 17:46
  • 1
    this 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 Jan 27 '21 at 01:47

1 Answers1

1

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.

cancerbero
  • 6,799
  • 1
  • 32
  • 24