我有这样的控制器,我正在使用 POSTMAN REST 客户端上传 pdf 文件。设置内容类型:multipart/form-data;boundary=randomBoundaryNotInAnyOfParts 它正在创建文件但没有在其中写入任何内容。我在这里错过了什么吗?
@RequestMapping(value = "/uploadfile", method = RequestMethod.POST)
public @ResponseBody String upload(HttpServletRequest request) {
InputStream is = null;
OutputStream out = null;
try {
is = request.getInputStream();
byte[] b = new byte[1024];
out = new FileOutputStream(new File("C:\\tmp\\upload.txt"));
out.write(b);
} catch (IOException e) {
e.printStackTrace();
} finally{
try{
if(out != null){
out.close();
}
if(is != null){
is.close();
}
}catch(IOException io){
io.printStackTrace();
}
}
return null;
}
谢谢, 维奈