Java 将文件从android上传到ftp服务器时出错

Java 将文件从android上传到ftp服务器时出错,java,android,ftp,Java,Android,Ftp,我正试图将一个图像从android上传到ftp服务器,但当我试图打开我上传的图像时,我看到的是以下消息,而不是图像“图像无法显示,因为它包含错误” 这就是我使用的代码 public void uploadImage(String path){ String server = "www.domainname.com"; int port = 21; String user = "ftp-username"; String pass

我正试图将一个图像从android上传到ftp服务器,但当我试图打开我上传的图像时,我看到的是以下消息,而不是图像“图像无法显示,因为它包含错误”

这就是我使用的代码

    public void uploadImage(String path){

     String server = "www.domainname.com";
        int port = 21;
        String user = "ftp-username";
        String pass = "ftp-password";

    FTPClient ftpClient = new FTPClient();
    try {

        ftpClient.connect(server, port);
        ftpClient.login(user, pass);
        ftpClient.enterLocalPassiveMode();


        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

        // APPROACH #1: uploads first file using an InputStream
        File firstLocalFile = new File(path);

        long fileSize = firstLocalFile.length();

        Log.i("File Size",fileSize+"");

        String firstRemoteFile = "testfile1.jpg";
        InputStream inputStream = new FileInputStream(firstLocalFile);

        Log.i("uploading", "Start uploading first file");
        boolean done = ftpClient.storeFile(firstRemoteFile, inputStream);
        inputStream.close();
        if (done) {
            Log.i("uploaded", "finished uploading first file");
        }

        // APPROACH #2: uploads second file using an OutputStream
        File secondLocalFile = new File(path);
        String secondRemoteFile = "testfile2.jpg";
        inputStream = new FileInputStream(secondLocalFile);

        Log.i("uploading", "Start uploading second file");
        OutputStream outputStream = ftpClient.storeFileStream(secondRemoteFile);
        byte[] bytesIn = new byte[4096];
        int read = 0;

        while ((read = inputStream.read(bytesIn)) != -1) {
            outputStream.write(bytesIn, 0, read);
        }
        inputStream.close();
        outputStream.close();

        boolean completed = ftpClient.completePendingCommand();
        if (completed) {
            Log.i("uploaded", "finished uploading second file");
        }

    } catch (IOException ex) {
        Log.i("Error", "Error: " + ex.getMessage());
        ex.printStackTrace();
    } finally {
        try {
            if (ftpClient.isConnected()) {
                ftpClient.logout();
                ftpClient.disconnect();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
错误在哪里


提前感谢。

这看起来很可疑,就像这个bug:


尝试改用。

在何处以及如何显示图像?请给出原始图像和上载图像的文件长度。在我上载图像后,我使用ftp用户名和密码登录到web主机,并双击图像,因此它应该显示在浏览器中,但我看到的是错误消息,而不是它,但是如果我尝试使用它的URL地址查看它,我会看到这个lawyer-book.com/Images/profiles/faditest.jpg请发布一个真正的链接,我们可以点击它。你不能使用ftp客户端吗?请找出长度。图像大小小于100KB,这是我上传的图像的真实链接。你必须提供两个长度。其中一份是原件,另一份是上传的。以字节为单位!不是KB。每个字节都计数。