1

I have a Restful JAX-RS Service which has a GET (/retrieve-pdfs) API which should respond with multiple PDF within the JSON response payload.

Example :

{
    "response": [{
            "pdf_name": "name_1.pdf",
            "File": "< pdf_data >"
        },
        {
            "pdf_name": "name_2.pdf",
            "File": "< pdf_data >"
        }
    ]
}

  1. If this is not the valid approach, Can someone let me know the right way to respond multiple pdfs
  2. The consumer is a Java application so Content-Disposition is not a requirement
Suman
  • 143
  • 1
  • 11
  • That's not what multipart is. You want to see a [real multipart response example](https://stackoverflow.com/a/50204061/2587435)? – Paul Samsotha Nov 25 '20 at 09:03

1 Answers1

0

I dont think it is possible to have a JSON response that includes PDF files.

Also I think it is not possible to download multiple files with just one request. Easiest way will be just but all the files in a *.zip file and than provide the *.zip file.

Here you have an easy example how create a *.zip file: Zip example

And here a good example how your controller should look like: Controller example

Mafick
  • 1,128
  • 1
  • 12
  • 27
  • can we have a JSON response with pdf content as an attribute with string format (base encoded)? Something like { "response": [{ "pdf_name": "name_1.pdf", "content": "sgdjnsdgk;..." }, { "pdf_name": "name_2.pdf", "content": "qwrkr;kmas.." } ] } – Suman Nov 25 '20 at 08:44
  • If not the JSON what are the other approaches to send multiple pdf as response @Mafick can you please let me know – Suman Nov 25 '20 at 08:51
  • Yes, it is quite common to base-64 encode a binary file (like a PDF) and return in JSON. It makes the JSON harder to read, but it works fine. Another alternative is to put the file somewhere and return a URL to download it. – Paul Jowett Mar 08 '21 at 06:34