Reputation: 107
My requirement is something like this. I have a DTO class as below
public class Employee{
private Long id;
private String name;
private String designation;
private byte[] employeeImage;
}
My API is below,
@PostMapping(value="/createEmployees")
public ResponseEntity<List<EmployeeDTO>> createEmployees(@RequestParam("id") Long id,
@RequestBody List<EmployeeDTO> employeeList){
}
I am trying to send a request using postman, but the image isn't getting saved. Below is my postman request.
Everything is fine, but image isn't getting saved.
Anyhelp is greatly appreciated.
Thanks in advance!
Upvotes: 0
Views: 862
Reputation: 1112
If you are sending Base 64 encoded image, then also decode it some thing like this :
//This will decode the String which is encoded by using Base64 class
byte[] imageByte=Base64.decodeBase64(imageByteValue);
String directory=servletContext.getRealPath("/")+"images/sample.jpg";
new FileOutputStream(directory).write(imageByte);
return "success ";
You should take your image from Employee DTO and decode it to save at its respective directory.
Upvotes: 2