使用Springboot在托管服务器上上传图像

时间:2018-12-07 12:56:10

标签: java spring-boot file-upload

我需要一些帮助来上传图片。

我有两个不同的应用程序

  • Springboot应用程序-在我的专用服务器上运行
  • Angular-6应用程序-在我的云服务器上运行

我需要将图像从spring-boot应用程序上传到Angular-6资产文件夹(资产文件夹类似于spring-boot应用程序的资源文件夹)

在application.properties中,我声明了上载位置,例如profile_path = D:/ documents / profile /(其工作文件带有“我的文件系统”路径)

    if (!profileImage.isEmpty()) {

        String fileName = profileImage.getOriginalFilename();
        String fileExtenstion = FilenameUtils.getExtension(fileName);

        InputStream is = profileImage.getInputStream();

        Files.copy(is, Paths.get(profile_path + userDetailId + "." + fileExtenstion),
                StandardCopyOption.REPLACE_EXISTING);

        profileImagePath = profile_path + userDetailId + "." + fileExtenstion;
    }

现在,问题出在云服务器路径上 如何在http://www.example.com/documents/profiles/或//103.XXX.XX.XX/documents/profiles/

上载

任何人都可以给我一个建议。

1 个答案:

答案 0 :(得分:0)

最后,我找到了以下解决方案。

解决方案1: 我们可以使用“ D:// Documents /”之类的路径将图像上传到文件系统上。我们只需要添加要上传图像的路径即可。

解决方案2: 我们可以使用“ file:////103.XXX.XX.XX//Documents/”之类的IP在服务器文件系统上上传图像。我们需要为偏远地区的路径提供IP地址。

解决方案3: 我们可以使用FTPClient(Java-Networking)将图像上传到我们的托管站点。 以下是参考: