1

我正在使用HttpClient上传我的文件。我尝试上传 19 个文件
,但只有 3 个文件成功上传。

请告诉我为什么这不起作用并在可能的情况下给我一些建议或代码示例?

我的代码如下:

public void uploadLog() {

new Thread(new Runnable() {
        @Override
        public void run() {


            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost(UPLOAD_LOG_URL);
            InputStreamEntity reqEntity;
            try {
                File file=new File(Environment.getExternalStorageDirectory()
                        + "/wlantest/report/");
                Log.v("report/", file.getCanonicalPath());
                File[] files=file.listFiles();
                for(int i=0;i<files.length;i++)
                {
                    reqEntity = new InputStreamEntity(new FileInputStream(
                            files[i].getCanonicalPath()), -1);
                    Log.v("test", "" + files[i].getCanonicalPath());
                reqEntity.setContentType("application/x-zip-compressed");
                reqEntity.setChunked(true);
                post.setEntity(reqEntity);
                HttpResponse response = client.execute(post);
                Log.v("test", "" + response.getStatusLine().toString());
                Log.v("test", "" + response.getStatusLine().getStatusCode());
                if (response.getStatusLine().getStatusCode() == 200) {
                    MainActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, "sucessed", Toast.LENGTH_SHORT).show();
                            File filetotal = new File(Environment.getExternalStorageDirectory() + "/wlantest/report/");
                            if (filetotal.listFiles().length != 0) {
                                report_total.setText("You have saved" + filetotal.listFiles().length
                                        + "reports" + "\n" + "click to upload");
                            }
                            else {
                                report_total.setText("You have no report\nafter saving will display");
                                progress.dismiss();
                            }

                        }
                    });
                }
                files[i].delete();

                }


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

            /*
             * sendMesssage(MESSAGE_FINISH, 0); } else {
             * sendMesssage(MESSAGE_FAILED, 0); } } catch (IOException e) {
             * e.printStackTrace(); sendMesssage(MESSAGE_FAILED, 0); }
             */

        }
    }).start();
}

和我的日志猫

11-01 14:34:25.110: V/test(874): HTTP/1.1 200 OK 11-01 14:34:25.110: V/test(874): 200 11-01 14:34:25.470: V/test (874):/mnt/sdcard/wlantest/report/1351643286085.zip 11-01 14:34:25.470:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:25.470:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:25.540: V/test(874): HTTP/1.1 200 OK 11-01 14:34:25.540: V/test(874): 200 11-01 14:34:25.550: V/test (874):/mnt/sdcard/wlantest/report/1351644284660.zip 11-01 14:34:25.550:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:25.550:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:25.630: V/test(874): HTTP/1.1 200 OK 11-01 14:34:25.630: V/test(874): 200 11-01 14:34:25.640: V/test(874): /mnt/sdcard/ wlantest/report/1351649375578.zip 11-01 14:34:25.640:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:25.640:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:25.790: V/test(874): HTTP/1.1 200 OK 11-01 14:34:25.790: V/test(874): 200 11-01 14:34:25.790: V/test (874):/mnt/sdcard/wlantest/report/1351650552047.zip 11-01 14:34:25.790:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:25.790:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:26.700:V/测试(874):HTTP/1。1 200 OK 11-01 14:34:26.700: V/test(874): 200 11-01 14:34:28.620: V/test(874): /mnt/sdcard/wlantest/report/1351652247364.zip 11- 01 14:34:28.640:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:28.640:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:28.780: V/test(874): HTTP/1.1 200 OK 11-01 14:34:28.780: V/test(874): 200 11-01 14:34:28.780: V/test (874):/mnt/sdcard/wlantest/report/1351652447759.zip 11-01 14:34:28.780:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:28.780:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:28.900: V/test(874): HTTP/1.1 200 OK 11-01 14: 34:28.900: V/test(874): 200 11-01 14:34:28.910: V/test(874): /mnt/sdcard/wlantest/report/1351652790670.zip 11-01 14:34:28.920: W /SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:28.920:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:28.940: V/test(874): HTTP/1.1 200 OK 11-01 14:34:28.940: V/test(874): 200 11-01 14:34:28.950: V/test (874):/mnt/sdcard/wlantest/report/1351652906642.zip 11-01 14:34:28.950:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:28.950:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.070: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.070: V/test(874): 200 11-01 14:34:29.080: V/test(874): /mnt/sdcard/wlantest/report/1351653878048.zip 11-01 14:34:29.090: W/SingleClientConnManager(874 ): SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.090:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.110: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.110: V/test(874): 200 11-01 14:34:29.110: V/test (874):/mnt/sdcard/wlantest/report/1351654209724.zip 11-01 14:34:29.110:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.110:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.200: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.200: V/test(874): 200 11-01 14:34:29.210: V/test(874): /mnt/sdcard/wlantest/report/1351661911878.zip 11-01 14:34:29.210: W/SingleClientConnManager(874): SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.210:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.310: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.310: V/test(874): 200 11-01 14:34:29.320: V/test (874):/mnt/sdcard/wlantest/report/1351662101340.zip 11-01 14:34:29.320:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.320:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.440: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.440: V/test(874): 200 11-01 14:34: 29.440:V/test(874):/mnt/sdcard/wlantest/report/1351662348097.zip 11-01 14:34:29.450:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.450:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.550: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.550: V/test(874): 200 11-01 14:34:29.550: V/test (874):/mnt/sdcard/wlantest/report/1351662414224.zip 11-01 14:34:29.560:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.560:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.650: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.650: V/test(874): 200 11-01 14:34:29.660: V/test (874): /mnt/sdcard/wlantest/report/1351662757528.zip 11-01 14:34:29.660:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.660:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.770: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.770: V/test(874): 200 11-01 14:34:29.770: V/test (874):/mnt/sdcard/wlantest/report/1351662878154.zip 11-01 14:34:29.780:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.780:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.810: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.810: V/test(874): 200 11-01 14:34:29.840: V/test (874): /mnt/sdcard/wlantest/report/1351663009338.zip 11-01 14:34:29.840:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.840:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.880: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.880: V/test(874): 200 11-01 14:34:29.880: V/test (874):/mnt/sdcard/wlantest/report/1351664456648.zip 11-01 14:34:29.880:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.880:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.920: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.920: V/test(874): 200 11-01 14:34:29.920: V/test (874): /mnt/sdcard/wlantest/report/1351665696886.zip 11-01 14:34:29.930:W/SingleClientConnManager(874):SingleClientConnManager 的使用无效:连接仍然分配。11-01 14:34:29.930:W/SingleClientConnManager(874):确保在分配另一个连接之前释放连接。11-01 14:34:29.960: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.960: V/test(874): 200 11-01 14:34:30.010: D/memalloc (874):离子:取消映射缓冲区基数:0x5d3d2000 大小:196608 11-01 14:34:30.010:D/memalloc(874):离子:取消映射缓冲区基数:0x5cf9a000 大小:196608 11-01 14:34:30.010:D /memalloc(874):离子:取消映射缓冲区基数:0x5cfca000 大小:196608 确保在分配另一个连接之前释放连接。11-01 14:34:29.960: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.960: V/test(874): 200 11-01 14:34:30.010: D/memalloc (874):离子:取消映射缓冲区基数:0x5d3d2000 大小:196608 11-01 14:34:30.010:D/memalloc(874):离子:取消映射缓冲区基数:0x5cf9a000 大小:196608 11-01 14:34:30.010:D /memalloc(874):离子:取消映射缓冲区基数:0x5cfca000 大小:196608 确保在分配另一个连接之前释放连接。11-01 14:34:29.960: V/test(874): HTTP/1.1 200 OK 11-01 14:34:29.960: V/test(874): 200 11-01 14:34:30.010: D/memalloc (874):离子:取消映射缓冲区基础:0x5d3d2000 大小:196608 11-01 14:34:30.010:D/memalloc(874):离子:取消映射缓冲区基础:0x5cf9a000 大小:196608 11-01 14:34:30.010:D /memalloc(874):离子:取消映射缓冲区基数:0x5cfca000 大小:196608

4

0 回答 0