0

按照我现在使用的代码。我能够发送到服务器,但无法将编码字符串转换为数据字节,因此无法将图像作为 blob 插入数据库中。我怎样才能做到这一点 ?

private void restWebServicesCall_updateJobDetail(String strScheduleGUID) {
    System.out.println("Inside od job info");
    HttpClient httpClient = new DefaultHttpClient();

    img_Sign.buildDrawingCache();
    Bitmap bm = img_Sign.getDrawingCache();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object   
    byte[] b = baos.toByteArray();

    String encodedImage = Base64.encodeToString(b , Base64.DEFAULT);


    try {
        JSONObject c = new JSONObject();
        // c.put("JobRef", strJobRef);
        c.put("ScheduleGUID", strScheduleGUID);
        c.put("OutcomeCode", "ACH");
        c.put("Report", txt_ReportedProblem.getText().toString().trim());
        c.put("Signee", edt_CustomerName.getText().toString().trim());
        c.put("ActDetails", "FixedEEE");
        c.put("StartDate", "2013-09-12 09:00:00");
        c.put("EndDate", "2013-09-15 17:00:00");
        c.put("Signature", encodedImage);

        System.out.println("Cc value : " + c.toString());
        StringEntity sendStuff = new StringEntity(c.toString());
        HttpPost omidPost = new HttpPost("web address");
        omidPost.setHeader("Accept", "*/*");
        omidPost.setHeader("Content-type", "application/json");
        omidPost.setHeader("Accept-Encoding", "gzip");
        omidPost.setHeader("Accept-Language", "en-US,en;q=0.8");
        omidPost.setEntity(sendStuff);
        HttpResponse postResponse = httpClient.execute(omidPost);
        String postText = EntityUtils.toString(postResponse.getEntity());
        Log.d("omid debug", "rest post response was " + postText);
        getJSON_Response(postText);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("Error : " + e.toString());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("Jsone Error : " + e.toString());
    }
}
4

0 回答 0