开云手机站登录入口成为热刺全球官方合作伙伴

4个月前 (04-21)

解决了这个问题加入到 为标签。 同题参见在那之后我可以把我的照片https://img02.100why.cn/HCT_20221122/20221122photo.png

解决方法

我已经在OpenShift服务器上部署了Spring MVC应用程序的.war
文件。 对照阅读每个用户都可以在那里更改照片。它在我的本地主机上工作,但是我需要在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";
}

但是这条路不起作用。日志文件显示了此异常

 /var/lib/openshift/56ae274f0c1e664bf3000158/jbossews/null/vr833vqI_wc.jpg
java.io.FileNotFoundException: null/vr833vqI_wc.jpg (No such file or directory)

请帮助!

总结

以上是真正的电脑专家为你收集整理的将照片上传到OpenShift。 相关阅读春季MVC的全部内容。希望文章能够帮你解决所遇到的问题。

如果觉得真正的电脑专家网站内容还不错,欢迎将真正的电脑专家推荐给好友。

你可能想看:

标签:string
分享给朋友:

继续阅读

若需了解「开云手机站登录入口成为热刺全球官方合作伙伴」的上下文,可结合站内栏目与相关篇目交叉阅读。

栏目用于追新,文内链接用于对照细节。两者配合可减少漏读与重复检索。

继续浏览时优先选择同栏目或相近主题,避免被站外镜像带偏。

站点导览

string · wiki · 科技 · 文化

页面按栏目组织。可先看导读,再进入相关篇目或返回列表。