4747import com .iemr .admin .utils .response .OutputResponse ;
4848
4949import io .swagger .v3 .oas .annotations .Operation ;
50+ import jakarta .servlet .http .HttpServletRequest ;
5051
5152
5253@ PropertySource ("classpath:application.properties" )
@@ -93,26 +94,19 @@ public ResponseEntity<byte[]> fetchFile(@PathVariable("userID") Long userID) thr
9394
9495 EmployeeSignature userSignID = employeeSignatureServiceImpl .fetchSignature (userID );
9596 HttpHeaders responseHeaders = new HttpHeaders ();
96- String fileName = URLEncoder .encode (userSignID .getFileName (), StandardCharsets .UTF_8 );
97-
98- responseHeaders .set (HttpHeaders .CONTENT_DISPOSITION ,
99- "attachment; filename=\" " + fileName + "\" ; filename*=UTF-8''" + fileName );
97+ ContentDisposition cd = ContentDisposition .attachment ()
98+ .filename (userSignID .getFileName (), StandardCharsets .UTF_8 ).build ();
99+ responseHeaders .setContentDisposition (cd );
100100
101101 MediaType mediaType ;
102102 try {
103- mediaType = MediaType .parseMediaType (userSignID .getFileType ());
103+ mediaType = MediaType .parseMediaType (userSignID .getFileType ());
104104 } catch (InvalidMediaTypeException | NullPointerException e ) {
105- mediaType = MediaType .APPLICATION_OCTET_STREAM ;
105+ mediaType = MediaType .APPLICATION_OCTET_STREAM ;
106106 }
107-
108107 byte [] fileBytes = userSignID .getSignature (); // MUST be byte[]
109-
110- return ResponseEntity .ok ()
111- .headers (responseHeaders )
112- .contentType (mediaType )
113- .contentLength (fileBytes .length )
114- .body (fileBytes );
115-
108+ return ResponseEntity .ok ().headers (responseHeaders ).contentType (mediaType ).contentLength (fileBytes .length )
109+ .body (fileBytes );
116110 } catch (Exception e ) {
117111 logger .error ("Unexpected error:" , e );
118112 logger .error ("File download for userID failed with exception " + e .getMessage (), e );
@@ -157,4 +151,4 @@ public String ActivateUser(@RequestBody String activateUser, HttpServletRequest
157151 }
158152 return response .toString ();
159153 }
160- }
154+ }
0 commit comments