1

Repository

// 'doc' is a blob type in oracle table
@Query(value =  "select doc from watever where ROWNUM = 1",  nativeQuery = true)
public byte[] findWatever();

Controller

byte[] reponse = dossierHypothecaireRepository.findWatever();               
HttpHeaders headers = new HttpHeaders();
headers.setContentLength(reponse.length);           
headers.setContentDispositionFormData("attachment", "out.pdf");
headers.setContentType(MediaType.parseMediaType("application/pdf"));
return new ResponseEntity<>(reponse, headers, HttpStatus.OK);   

Problem

When I call this controller from a browser and want to display the pdf I get "pdf wont display" or "corrupt file"

I tried with many differents pdfs, browsers and pdfreaders: same error.

=> the problem comes from my code I think.

Edit additional information: The file I put in base for my test is : 430 ko The downloaded file from the browser is : 420 ko

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Tyvain
  • 2,640
  • 6
  • 36
  • 70
  • 1
    true, but actually it's Boba Fett from star wars ;) - https://fr.wikipedia.org/wiki/Boba_Fett – Tyvain Nov 15 '17 at 03:48
  • along with data you have to pass the format, file Name, file size. here is the simple example https://www.javatpoint.com/how-to-write-data-into-PDF-using-servlet – Nidhi257 Nov 15 '17 at 03:49
  • I tried with this solution for example: https://stackoverflow.com/questions/16652760/return-generated-pdf-using-spring-mvc => still the same error. – Tyvain Nov 15 '17 at 04:02
  • @Tyvain have you tried downloading complete file before opening it? – Saravana Nov 15 '17 at 04:02
  • @Saravana yes, I just tried (see edited code). Can't open the downloaded pdf.. :( – Tyvain Nov 15 '17 at 04:07
  • So how does the original pdf and the downloaded differ? How do they compare to what is stored in the DB? – Jens Schauder Jan 11 '18 at 13:09

0 Answers0