controller
/**
* MultipartFile Automatic encapsulation of uploaded files
* @param email
* @param username
* @param headerImg
* @param photos
* @return
*/
@PostMapping("/upload")
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={}",
email,username,headerImg.getSize(),photos.length);
if(!headerImg.isEmpty()){
String originalFilename = headerImg.getOriginalFilename();
headerImg.transferTo(new File("D:\\cache\\"+originalFilename));
}
if(photos.length > 0){
for (MultipartFile photo : photos) {
if(!photo.isEmpty()){
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:
- [Solved] Spring upload file Error: Multipartfile Transferto() reported an error FileNotFoundException
- After asynchronous file import and springboot multipartfile upload, the @async asynchronous processing reports an error: nosuchfileexception
- Springboot Files Upload Limit Error: The field file exceeds its maximum permitted size of 1048576 bytes
- [Solved] Pycharm Failed to Upload: Upload to *** failed. Could not list the contents of folder “sftp
- JAVA: How to Use Multipartfile to upload Files
- SpringCloud Use openFeign Multipartfile to Upload Files Error: Current request is not a multipart request
- [Solved] Springboot upload failed to find the temporary directory error
- Tomcat cross server upload error 403forbidden [How to Solve]
- JAVA: How to Use Minio to upload pictures
- How to Solve Springboot Upload Files Error: The field XXX exceeds its maximum permitted size of 1048576 bytes
- How to Solve Image Upload Error: Uncaught (in promise) DOMException: Failed to execute ‘put‘ on ‘IDBObjectStore‘
- [Solved] Upload Files Error: Request processing failed;nested exception is org.springframework.web.multipart.MultipartExcepti
- How to Upload Docker Image to docker hub
- Multipartfiletofileutils (multipartfile to file)
- [Solved] Kafka in Windows error:java. nio. file. Filesystemexception: this file is in use by another program and cannot be accessed by the process
- JAVA: Random access file is always garbled
- How to Download File via Response (Example Code)
- Java parsing xml file encounters special symbols & will be abnormal solutions
- Java will convert Excel to list set or JSON, export excel file to local, excel import and export, easyexcel tool class
- [Solved] ln: failed to create symbolic link ‘/usr/bin/java’: File exists