public String MultipartUpload(String url,MultipartHttpServletRequest multiRequest) { List<MultipartFile> multipartFiles = multiRequest.getFiles("files");
MultipartFile multipartFile = null;
String fileName,fix;
File tempFile;
BufferedOutputStream bufferedOutputStream = null; for (int i = 0; i < multipartFiles.size(); ++i) { multipartFile = multipartFiles.get(i); if (!multipartFile.isEmpty()) { fix=getFix(multipartFile.getOriginalFilename());
fileName=new Date().getTime()+fix;
String path = url+"/"+fileName;
tempFile=new File(path); if (!tempFile.getParentFile().exists()) { tempFile.getParentFile().mkdirs();
}
try { bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(tempFile)); byte[] bytes = multipartFile.getBytes();
bufferedOutputStream.write(bytes, 0, bytes.length);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) { e.printStackTrace();
}
} else { System.out.println("上传的文件为空");
} System.out.println("上传文件完成了");
}
return "request ok";
|