0

Downloading a file with this client method:

    @GET
    @Path("/download")
    @Produces(APPLICATION_PDF)
    fun getDocument(): ByteArray

I get bytes as [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, -17, -65, -67, ... more] The PDF file is corrupted.

Downloading the same file with a curl

curl --request GET      --url https://api.app/download      --header 'accept: application/pdf' -o doc.pdf

I get bytes as [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, -30, -29, -49, ... more] The PDF file is fine.

I don't see what I can do to fix this.

In the logs I do see the query flying with proper headers:

DEBUG [org.jbo.res.rea.cli.log.DefaultClientLogger] (vert.x-eventloop-thread-0) MDC[ps= rpm= capi=] Request: GET https://api.app/download Headers[Accept=application/pdf User-Agent=MyServiceAPI (- / -) X-CorrelationID=srv00014.out01], Empty body
DEBUG [org.jbo.res.rea.cli.log.DefaultClientLogger] (vert.x-eventloop-thread-0) MDC[ps= rpm= capi=] Response: GET https://api.app/download, Status[200 OK], Headers[Access-Control-Allow-Origin=* Allow=GET Cache-Control=no-cache, private Content-Disposition=attachment; filename=doc.pdf Content-Type=application/pdf <other meaningless headers>], Body:
brisssou
  • 499
  • 6
  • 12

1 Answers1

0
    @GET
    @Path("/download")
    @Produces(APPLICATION_PDF)
    fun getDocument(): File

is working much better, but it creates the file in /tmp which is not great, but at least I stick to the REST client.

brisssou
  • 499
  • 6
  • 12
  • The file is likely created as it doesn't want to keep all the bytes in memory as that could cause issues. The file should likely get deleted. – James R. Perkins Aug 31 '23 at 18:38