将照片上传到OpenShift。 Spring MVC
我在OpenShift服务器上部署了我的Spring MVC应用程序的.war文件。 每个用户都可以更改照片。 它适用于我的localhost,但我需要在OpenShift服务器上传照片并将每张照片的路径放到数据库中。 这是我上传文件的方法
@RequestMapping(value = "/user/updateinfo", method = RequestMethod.POST) public String postAvatar(@RequestParam("file") MultipartFile file, Principal principal) { if (file.isEmpty()) { return "redirect:/user"; } if (!file.isEmpty()) { try { String relativeWebPath = "/resources/avatars/"; String absoluteFilePath = context.getRealPath(relativeWebPath); String name = file.getOriginalFilename(); // String name=file.getOriginalFilename(); System.out.println(absoluteFilePath); String path = absoluteFilePath + "/" + name; File convFile = new File(absoluteFilePath + "/" + name); this.usersService.addUserAvatar(principal.getName(), "/var/lib/openshift/56ae274f0c1e664bf3000158/app-root/data/"+name); System.out.println(convFile.getAbsolutePath()); file.transferTo(convFile); System.out.println("You have uploaded file"); return "redirect:/user"; } catch (Exception e) { e.printStackTrace(); System.out.println("Failed to upload"); return "redirect:/user"; } } return " redirect:/user"; }
但这条道路不起作用。 日志文件向我显示此exception
/var/lib/openshift/56ae274f0c1e664bf3000158/jbossews/null/vr833vqI_wc.jpg java.io.FileNotFoundException: null/vr833vqI_wc.jpg (No such file or directory)
请帮助!
解决了这个问题,将
到.openshift / config / server.xml到
标记中。 之后,我可以通过http://sofzh.miximages.com/java/photo.jpg
获取我的照片
- 如何使用selenium或webdriver处理测试自动化中的文件上载
- 为什么这个exceptionFileItemStream $ ItemSkippedException?
- 如何使用Commons FileUpload设置用于存储文件上载的文件夹
- 在struts1中上传文件
- ServletFileUpload #parseRequest(request)返回一个空列表
- 如何在不传输整个文件的情况下限制使用JavaScript(或Java)上载的文件的大小?
- 使用Selenium WebDriver进行PrimeFaces fileUpload测试
- 使用HTTPHandler进行文件上传
- Spring FileUpload问题