Spring boot 将图像上载到ftp服务器后无法打开-格式已更改

Spring boot 将图像上载到ftp服务器后无法打开-格式已更改,spring-boot,ftp,upload,thymeleaf,file-format,Spring Boot,Ftp,Upload,Thymeleaf,File Format,我的spring boot应用程序有问题。 当我上传一个文件到我的ftp服务器时,该文件会以某种方式改变其格式。 我再也无法打开这些图片了 我通过thymeleaf上传它们。 在控制器中,我使用上传服务`和以下方法: public void fileUpload(MultipartFile file) { try { FtpClient ftp = new FtpClient(ftpHost, ftpPort, ftpUser, ftpPasswo

我的spring boot应用程序有问题。 当我上传一个文件到我的ftp服务器时,该文件会以某种方式改变其格式。 我再也无法打开这些图片了

我通过thymeleaf上传它们。
在控制器中,我使用上传服务`和以下方法:

    public void fileUpload(MultipartFile file) {
        try {
            FtpClient ftp = new FtpClient(ftpHost, ftpPort, ftpUser, ftpPassword);
            ftp.open();
            String tmpdir = System.getProperty("java.io.tmpdir");
            File physicalFile = new File(tmpdir+file.getOriginalFilename());
            file.transferTo(physicalFile);
            ftp.putFileToPath(physicalFile, file.getOriginalFilename());
            ftp.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
}
以下是我的FtpClient方法:

public void open() throws IOException {
    ftp = new FTPClient();

    ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

    ftp.connect(server, port);
    int reply = ftp.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        ftp.disconnect();
        throw new IOException("Exception in connecting to FTP Server");
    }

    ftp.login(user, password);
}

public void close() throws IOException {
    ftp.disconnect();
}

public void putFileToPath(File file, String path) throws IOException {
    ftp.storeFile(path, new FileInputStream(file));
}
一切正常-文件出现在服务器上,甚至具有相同的权重。
... 但是我不能打开它。
任何我试图打开它的图形程序都会说它是错误的文件格式


有什么想法吗?

在我的FtpClient类中-我添加了一行
在void open()方法中:

public void open() throws IOException {
    ftp = new FTPClient();

    ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
    ftp.connect(server, port);
    int reply = ftp.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        ftp.disconnect();
        throw new IOException("Exception in connecting to FTP Server");
    }

    ftp.login(user, password);

    //      IT WAS THE PROBLEM - I didn't have it:
    ftp.setFileType(FTP.BINARY_FILE_TYPE);

}

感谢您的帮助

从什么时候开始,一个文件有“权重”?自从Newton发现重力以来,您确定这两个文件(本地和远程)的大小相同(以字节为单位!),如果没有,查看关于
setFileTypd
的内容,实际上我已经检查过了,差别就像是1个字节,使用
filetype
可以将ASCII转换为二进制传输。您需要将此文件传输到二进制文件以保持相同的大小。(我不知道这是否也会改变重量