我的要求是这样的。我有一个如下的DTO课程
public class Employee{
private Long id;
private String name;
private String designation;
private byte[] employeeImage;
}
我的API在下面,
@PostMapping(value="/createEmployees")
public ResponseEntity<List<EmployeeDTO>> createEmployees(@RequestParam("id") Long id,
@RequestBody List<EmployeeDTO> employeeList){
}
我正在尝试使用邮递员发送请求,但是图像未保存。以下是我的邮递员请求。
一切都很好,但是图像没有保存。
非常感谢任何帮助。
谢谢!
答案 0 :(得分:2)
如果您要发送Base 64编码的图像,则还要对它进行解码,如下所示:
//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 ";
您应该从Employee DTO中获取图像并对其进行解码以保存在其各自的目录中。