oom崩溃了现在改用httpurlconnection

解决方案 »

  1.   

    /**
     * 上传文件
     * @param file
     * @return
     * @throws Exception
     */
    public Json uploadLocal(File file) throws Exception {
    fileSize = (int) file.length();
    if (null != progress) {progress.setMax(fileSize);}
    String url = "http://192.168.1.58:8088/test/other/httpTakeFile.htm";
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setDoOutput(true);conn.setDoInput(true);
    conn.setChunkedStreamingMode(1024 * 1024);
    conn.setRequestMethod(Domain.REQUEST_POST);
    conn.setRequestProperty("connection", "Keep-Alive");
    conn.setRequestProperty("Charsert", HTTP.UTF_8);
    conn.setRequestProperty("Content-Type", "multipart/form-data;file=" + file.getName());
    conn.setRequestProperty("ext", file.getName().substring(file.getName().lastIndexOf(".")));
    OutputStream output = conn.getOutputStream();InputStream input = new FileInputStream(file);
    int i = 0, total = 0;
    byte[] buffer = new byte[1024];
    while ((i = input.read(buffer)) != -1) {
    output.write(buffer, 0, i);
    total += i;
    if (null != progress) {progress.setProgress(total);}
    }
    String response = readFile(conn.getInputStream(), HTTP.UTF_8, 1, false);
    input.close();output.flush();output.close();conn.disconnect();
    JSONObject object = new JSONObject(response);
    Json vo = new Json(object.getBoolean("success"), object.getString("message"));
    JSONObject data = null;try {data = (JSONObject) object.get("data");} catch (Exception e) {}
    if (null != data) {
    Iterator iterator = data.keys();
    while (iterator.hasNext()) {
    String key = (String) iterator.next();vo.getData().put(key, data.get(key));
    }
    }
    return vo;
    }
    带进度条上传文件,文件大小通吃
      

  2.   


    MultipartEntity这些都是在apache官网有源码的,下来代码调试一下,找到问题所在,也可为开源社区做点贡献。