从OpenShift服务器获取图像路径. Spring MVC. JSP [英] Get image path from OpenShift server. Spring MVC. JSP

查看:121
本文介绍了从OpenShift服务器获取图像路径. Spring MVC. JSP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从OpenShift服务器获取照片路径时遇到麻烦. 我有一个已经部署在OpenShift服务器上的Spring MVC应用程序. 在那里,每个用户都可以在此处下载个人资料照片.我是这样的.

I have got a trouble while getting photo path from OpenShift server. I have got a Spring MVC app that have deployed at OpenShift server. There, every user could download there profile pics. I do it this way.

@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 = "";
            String absoluteFilePath = "/var/lib/openshift/56ae274f0c1e664bf3000158/app-root/data/";
            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";
}

我将文件放置在OpenShift服务器上的此路径

I'm putting my files to this path at OpenShift server

/var/lib/openshift/56ae274f0c1e664bf3000158/app-root/data/

然后,我将需要到达用户页面的该图像的路径放入数据库中

And after that i'm putting to database a path to this image that needed to get at user's page

this.usersService.addUserAvatar(principal.getName(),"/var/lib/openshift/56ae274f0c1e664bf3000158/app-root/data/"+name);

当我打开用户页面时,它向我显示GET https://appName-domain.rhcloud.com/haine/var/lib/openshift/56ae274f0c1e664bf3000158/app-root/data/vr833vqI_wc.jpg

When i'm opening user's page it shows me 404 error that GET https://appName-domain.rhcloud.com/haine/var/lib/openshift/56ae274f0c1e664bf3000158/app-root/data/vr833vqI_wc.jpg

如何为我的照片添加一条可以访问的当前路径?请帮助!

How to put a current path to my photos that it could have an access? Help pls!

推荐答案

此操作方法说明了为什么在openshift上很难从Java应用程序提供用户上传的文件,以及可以使用哪些代码来纠正这种情况: https://forums.openshift .com/how-to-to-upload-and-serve-files-using-java-servlets-on-openshift

This how-to explains why it is difficult to serve user-uploaded files from a java application on openshift, and what code you can use to remedy the situation: https://forums.openshift.com/how-to-upload-and-serve-files-using-java-servlets-on-openshift

这篇关于从OpenShift服务器获取图像路径. Spring MVC. JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆