/*
* 文件上传
*
*/
@RequestMapping(value = "upload", method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> upload(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request,
HttpServletResponse response) throws IOException {
String url = upload;
HessianProxyFactory factory = new HessianProxyFactory();
IBigFileService bigfile = null;
bigfile = (IBigFileService) factory.create(IBigFileService.class, url);
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, Object> listMap = new HashMap<String, Object>();
MultipartFile mFile = multipartRequest.getFile("file");// 得到上传的文件
String bigfileguid = null;
if (mFile != null) {
Long change = mFile.getSize();
System.out.println("*********&&&&&^^^^%%%%%%%%%"+change);
int KB = (int) (change / 1024);//// 转化为KB;
int M = (int) (KB / 1024);//// 转化为M;
if (M > 10) {// 10M大小
listMap.put("id", bigfileguid);
listMap.put("flag", "文件上传大小受到限制");
} else {
// 得到上传的文件的文件名
String filename = mFile.getOriginalFilename();
InputStream inputStream = mFile.getInputStream();
byte[] bigfiledata = new byte[inputStream.available()];
bigfileguid = bigfile.saveBigFileInfo(fileSchema, 02, "13000000", filename, "{\"exe\":\"doc\"}".getBytes(),
"sd");
while ((inputStream.read(bigfiledata, 0, bigfiledata.length)) != -1) {
bigfile.saveBigFileData(fileSchema, 1, bigfileguid, bigfiledata);
}
inputStream.close();
if (bigfileguid != null) {
System.out.println("***********&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&77777777777777777777"+bigfileguid);
listMap.put("id", bigfileguid);
listMap.put("fileName",filename);
listMap.put("flag", "上传成功");
}
}
}
System.out.println("111111111111111111112344444455555566666667"+listMap);
return listMap;
}
111111111111111111112344444455555566666667{id=913e2285-a997-4a9b-918c-af9fcac8afb0, flag=上传成功, fileName=免费源码网站注册地址.txt}
DEBUG - Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> heb.trainArchives.controller.FileController.upload(org.springframework.web.multipart.MultipartFile,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
DEBUG - Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> heb.trainArchives.controller.FileController.upload(org.springframework.web.multipart.MultipartFile,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
DEBUG - Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> heb.trainArchives.controller.FileController.upload(org.springframework.web.multipart.MultipartFile,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
DEBUG - Null ModelAndView returned to DispatcherServlet with name 'DispatcherServlet': assuming HandlerAdapter completed request handling
DEBUG - Cleaning up multipart file [file] with original filename [免费源码网站注册地址.txt], stored in memory
DEBUG - Successfully completed request
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
后端方法接口要加上produces=MediaType.TEXT_PLAIN_VALUE,而且返回值是String类型,可以参考这篇文章:https://blog.csdn.net/li396864285/article/details/52815822