Upload file error analysis standardmultiparthttpservletrequest


 * MultipartFile Automatic encapsulation of uploaded files
 * @param email
 * @param username
 * @param headerImg
 * @param photos
 * @return
public String upload(@RequestParam("email") String email,
                     @RequestParam("username") String username,
                     @RequestPart("headerImg") MultipartFile headerImg,
                     @RequestPart("photos") MultipartFile[] photos) throws IOException {

    log.info("Upload the message:email={},username={},headerImg={},photos={}",

        String originalFilename = headerImg.getOriginalFilename();
        headerImg.transferTo(new File("D:\\cache\\"+originalFilename));

    if(photos.length > 0){
        for (MultipartFile photo : photos) {
                String originalFilename = photo.getOriginalFilename();
                photo.transferTo(new File("D:\\cache\\1"+originalFilename));

    return "main";

Common errors:

New file (“D: \ cache \ 1” + originalfilename “), there is no duplicate disk file name

Debug the debug mode and enter the transferto method. It is found that the source code is to judge whether the file exists

debug mode evaluate expression. Open the expression debugging window and see the error

Read More: