多文件上傳,參數是album
for (MultipartFile file : album) {
temp_photoName=file.getOriginalFilename();
System.out.println("upload pic:"+temp_photoName);
File photo = new File(path, temp_photoName);
if (!photo.exists()) {
try {
photo.createNewFile();
FileUtils.writeByteArrayToFile(photo, file.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}
前端如果用post請求來上傳文件的時候,注意定義在後臺的多文件的參數名。