一次性上传,就会内存溢出.那么,我想问问,怎么把图片分块上传.代码应该怎么写..

解决方案 »

  1.   

    new Thread() {
    @Override
    public void run() {
    // 文件存在,开始上传
    try {
    FileInputStream fis = new FileInputStream(photoPath);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int count = 0;
    while ((count = fis.read(buffer)) >= 0) {
    baos.write(buffer, 0, count);
    }
    // 进行Base64编码
    uploadBuffer = new String(Base64.encode(data));
    uploadBuffer = new String(Base64.encode(baos.toByteArray()));
    Log.i("uploadBuffer", uploadBuffer);
    String methodName = "uploadImage";
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
    Date date = new Date();
    String time = format.format(date);
    String fileName = "紧急报送" + "img" + time + ".jpg";
    String des = describe.getText().toString();
    if (des.equals("")) {
    des = fileName;
    }
    Log.i("describe", des);
    // 调用webservice
    Log.i(TAG, longitude + " : " + latitude);
    if (WebServiceUtils.uploadEventAttachment("uploadImage2",userStatus, unitCode, EMSConstant.PHONENUMBER, "",
    fileName, uploadBuffer, eventId, des, longitude, latitude).equals("OK")) {
    // 向handlerPhoto发消息
    handlerPhoto.sendEmptyMessage(SUCCEED);
    } else {
    handlerPhoto.sendEmptyMessage(FAIL);
    }
    baos.close();
    fis.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }.start();
      

  2.   

    public static String uploadEventAttachment(String methodName, String YHDLM, String unitCode,String phoneNumber, String identifier, String fileName,
    String data, String eventId, String siteDesc,int longitude,int latitude) {
    // 以下就是调用过程了,不明白的话 请看相关webservice文档
    SoapObject soapObject = new SoapObject(namespace, methodName);
    soapObject.addProperty("YHDLM", YHDLM);
    soapObject.addProperty("PhoneNumber", phoneNumber);
    soapObject.addProperty("Identifier", identifier);
    soapObject.addProperty("FileName", fileName); // 参数1 图片名
    soapObject.addProperty("Data", data); // 参数2 图片字符串
    soapObject.addProperty("EventID", eventId);
    soapObject.addProperty("SiteDesc", siteDesc);
    soapObject.addProperty("dwdm", unitCode);
    soapObject.addProperty("Longitude", longitude);
    soapObject.addProperty("Latitude", latitude);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    envelope.bodyOut = soapObject;
    envelope.dotNet = true;
    String respone = "";
    // envelope.setOutputSoapObject(soapObject);
    HttpTransportSE httpTranstation = new HttpTransportSE(url);
    try {
    httpTranstation.call(namespace + methodName, envelope);
    Object result = envelope.getResponse();
    Log.i(TAG, "uploadEventAttachment: " + result.toString());
    respone = result.toString();
    } catch (Exception e) {
    e.printStackTrace();
    return "Fail";
    }
    return respone; }
      

  3.   

    没看到分块 只看到 把图片base64编码为字符 然后用webservice上传。
    如果你要图片分块的话:大概思路是 做一个私有协议,定义好文件的块数,图片的名称,二进制的数据,然后上传就可以
      

  4.   

    怎么做一个私有协议.这个我不会...HELP.大神