将照片从Android更新到FTP时出错

时间:2014-05-15 15:14:37

标签: android image ftp

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

Random image to upload

(要上传的随机图片)

Random image uploaded

(图片已上传)

代码:`class Sender扩展了AsyncTask     {     档案照片;     public Sender(档案照片){         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);

    }
}`

我做错了什么?很多

1 个答案:

答案 0 :(得分:0)

这是因为我上传了像ASCII而不是二进制的图像。它只是一个配置参数:

ftpClient.setFileType(FTP.BINARY_FILE_TYPE);