【问题标题】:Error updating photo from Android to FTP将照片从 Android 更新到 FTP 时出错
【发布时间】:2014-05-15 15:14:37
【问题描述】:

我按照一本手册将图像从 Android 上传到 FTP。如果我尝试更新已拍摄的照片,我在 FTP 文件上看不到任何内容。它创建并且大小还可以,但不包含任何内容。然后我尝试上传一张小图片,结果如下:

(随机图片上传)

(图片上传)

代码:`class Sender extends AsyncTask { 档案照片; 公共发件人(档案照片){ this.photo=照片;

}


    protected String doInBackground(String... params) 
    {
        FTPClient ftpClient = new FTPClient();
        try {
            ftpClient.connect(InetAddress.getByName("ftp.fercode.com"));
            ftpClient.login(xxx","xxx");
            Boolean result = ftpClient.changeWorkingDirectory("/img");
            Log.e("existeix carpeta?",result.toString() );


        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        InputStream srcFileStream=null;
        try {

            srcFileStream = new FileInputStream(photo.getAbsolutePath());

        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            //ftpClient.stor(photo.getAbsolutePath());

             boolean status = ftpClient.storeFile("/img/imagePrueba.jpeg",  
                    srcFileStream);  
            Log.e("Status", String.valueOf(status));  
            srcFileStream.close(); 
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  


        // TODO Auto-generated method stub


        return null;

    } 
    @Override
    protected void onPreExecute() 
    {
        super.onPreExecute();

    }

    @Override
    protected void onPostExecute(String result)
    {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

    }
}`

我做错了什么?非常感谢

【问题讨论】:

    标签: android image ftp


    【解决方案1】:

    发生这种情况是因为我上传的是 ASCII 而不是二进制的图像。这只是一个配置参数:

    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

    【讨论】:

      猜你喜欢
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-27
      • 2019-05-01
      相关资源
      最近更新 更多