0

I am trying to create a RESTController in a SpringBoot application which will return a zip file as an attachment and a JSON body containing metadata about the zip file, both in the same REST response.

I tried to find examples for Multipart download but most of the examples are about file upload with json body in request. So far I have encountered below post only which seems relevant but does not look elegant as it requires client side specific libraries to receive the response properly.

Can I send an excel file and JSON body with a description of file in same REST API Response

Is there any elegant way to achieve this in SpringBoot where client side implementation is not required? Any pointers on this is appreciated.

user1144004
  • 183
  • 3
  • 4
  • 21
  • 1
    Response is simple: everything is possible if your client is able to manage what you send. So think the opposite side of your question : ask yourself how your client can manage 2 object in response of one query. If you manage the client, there is no problem, if you want to use standard client, then you already have your answer : it is not possible. – wargre Dec 31 '20 at 19:39
  • @wargre I was hoping if there was any specification by which a standard client (like browser) would understand the content based on its actual type. I guess there's nothing like that. – user1144004 Dec 31 '20 at 21:27
  • In http/2 format, you have a "push" option, BUT there is a catch, it only works for resources a browser manage (css/image ...) here you want json + zip so you have to manage something. At this point you'd better add a data attribute with the base64 file and manage everything on client side. – wargre Jan 01 '21 at 10:17

0 Answers0