我正在尝试使用Apache Commons将图像保存到FTPServer中 FTPClient.storeFile(...) 方法,它需要 InputStream 。图像以 Byte[] 在一开始。
FTPClient.storeFile(...)
InputStream
Byte[]
以下是一些代码:
InputStream is = new ByteArrayInputStream(byteArray); boolean done = ftpClient.storeFile(remotePath, is);
然而,当我下载上传的图像时,它看起来很奇怪,即使尺寸得到尊重,图像看起来也不应该。 上传后的图像如下所示: Image after uploading 事实上,我无法接触到原始图像,但我知道这是一幅开阔大海的图像,上面有蓝色的海水。 非常感谢。
所以,作为 VGR 哦!准确地指出,Apache Commons ftpClient有两种工作模式,ASCII和二进制模式。默认情况下,使用ASCII模式,必须通过
try { ftpClient.setFileType(FTP.BINARY_FILE_TYPE); } catch (IOException ex) { System.out.println("Error: " + ex.getMessage()); ex.printStackTrace(); }