如何在SpringBoot中将大文件上传到ftps服务器?

问题描述 投票:1回答:1

我想将文件上传到ftps服务器。以下代码适用于10KB之类的小文件。但我需要上传5-10 MB的文件。错误在错误行下方。有人可以帮我弄这个吗?下面我尝试过的代码。有更好的方法吗?

错误线

boolean result = con.storeFile(FILE_NAME, multipartFile.getInputStream());

CODE

    public void createDeviceVersion(MultipartFile multipartFile) {

        String FTP_ADDRESS = backendConfigRepo.findByConfigKey(KeyConstant.FTP_ADDRESS).getConfigValue();
        int FTP_PORT = Integer.parseInt(backendConfigRepo.findByConfigKey(KeyConstant.FTP_PORT).getConfigValue());
        String USER = backendConfigRepo.findByConfigKey(KeyConstant.FTP_USER).getConfigValue();
        String PASSWORD = backendConfigRepo.findByConfigKey(KeyConstant.FTP_PASSWORD).getConfigValue();
        String FILE_NAME = backendConfigRepo.findByConfigKey(KeyConstant.MCASH_VERSION_FILE_NAME).getConfigValue();
        FTPSClient con = null;

        try {
            con = new FTPSClient(true);
            con.connect(FTP_ADDRESS, FTP_PORT);

            if (con.login(USER, PASSWORD)) {
                con.enterLocalPassiveMode();
                con.setFileType(FTP.BINARY_FILE_TYPE);
                boolean result = con.storeFile(FILE_NAME, multipartFile.getInputStream());
                System.out.println(result);
                con.logout();
                con.disconnect();

            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

错误MSG

org.apache.commons.net.io.CopyStreamException: IOException caught while copying.
    at org.apache.commons.net.io.Util.copyStream(Util.java:136)
    at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:675)
    at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:639)
    at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:2160)
    ....
Caused by: java.net.SocketException: Connection reset by peer: socket write error
....
java spring-boot ftps
1个回答
0
投票

您是否尝试过更改webapps/manager/WEB-INF/web.xml中的最大尺寸?我认为这可能对您有帮助enter link description here

© www.soinside.com 2019 - 2024. All rights reserved.