2

My front end Looks Like:

<form method="post" enctype="multipart/form-data" action=".../user/doUpload">
        <input type="file" name="file"/>
        <button  type="Submit">Submit</button>

My spring controller looks like -

@RequestMapping(value = "/doUpload", method = RequestMethod.POST)
    public String handleFileUpload(HttpServletRequest request,
            @RequestParam(value="file", required=true) CommonsMultipartFile[] fileUpload) throws Exception {         UserService userService = ApplicationBeanFactory.getBean(UserService.class);        User user=new User();
        if (fileUpload != null && fileUpload.length > 0) {
            for (CommonsMultipartFile aFile : fileUpload){

                System.out.println("Saving file: " + aFile.getOriginalFilename());

                UserModel userModel=new UserModel();
                userModel.setImageName(aFile.getOriginalFilename());
                userModel.setImageData(aFile.getBytes());
                user= userService.save(userModel);               
            }
        }

        return "Success";
    }

Getting error Like :

The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.

Shifat
  • 732
  • 1
  • 6
  • 20

0 Answers0