0

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.

Postman Request

Everything is fine, but image isn't getting saved.

Anyhelp is greatly appreciated.

Thanks in advance!

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.