SpringBoot上传文件(MultipartFile)

支持的请求类型:multipart/form-data

接收参数对象类型:MultipartFile

参考代码:

@PostMapping(path = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseBody
public void uploadFile(@RequestParam("file") MultipartFile file) {
    if (file.isEmpty()) {
        return;
    }
    
    BufferedReader reader = null;
    try {
         reader = new BufferedReader(new InputStreamReader(file.getInputStream()));
         String str;
         while ((str = reader.readLine()) != null) {
            System.out.println(str);
         }
     } catch (IOException e) {
         log.error("exception", e);
     } finally {
         IOUtils.closeQuietly(reader);
     }
}

 

你可能感兴趣的:(SpringBoot,spring,boot,spring,java)