簡體   English   中英

從OpenShift服務器獲取圖像路徑。 Spring MVC。 JSP

[英]Get image path from OpenShift server. Spring MVC. JSP

從OpenShift服務器獲取照片路徑時遇到麻煩。 我有一個已經部署在OpenShift服務器上的Spring MVC應用程序。 在那里,每個用戶都可以在那里下載個人資料照片。 我是這樣的。

@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服務器的此路徑中

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

之后,我將需要到達用戶頁面的該圖像的路徑放入數據庫中

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

當我打開用戶頁面時,它顯示404錯誤,即GET https://appName-domain.rhcloud.com/haine/var/lib/openshift/56ae274f0c1e664bf3000158/app-root/data/vr833vqI_wc.jpg

如何為我的照片設置當前可以訪問的路徑? 請幫助!

此方法說明解釋了為什么在openshift上很難從Java應用程序提供用戶上傳的文件,以及可以使用哪些代碼來糾正這種情況: https ://forums.openshift.com/how-to-upload-and -serve -文件-使用的Java-的servlet-ON-openshift

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM