中創建Blob密鑰我想將攝像頭捕獲的圖像發送到服務器,該服務器會創建blob密鑰。我沒有得到如何將該映像發送到服務器。圖像是以哪種格式發送的?發送圖像到服務器以在android
我想通過HttpParams
發送參數。
這是我的代碼,但數據不會去服務器。問題是什麼?
String name=tname.getText().toString();
String addr=taddr.getText().toString();
String age=tage.getText().toString();
String cnct=tcnct.getText().toString();
String gen=tgen.getText().toString();
String wtm=twtm.getText().toString();
ba1=Base64.encodeToString(imageform, 0);
Date d=new Date();
String date=d.toString();
InputStream i1;
String back="";
HttpParams p=new BasicHttpParams();
p.setParameter("vname",name);
p.setParameter("address", addr);
p.setParameter("age", age);
p.setParameter("contact", cnct);
p.setParameter("gender", gen);
p.setParameter("whomto", wtm);
p.setParameter("myFile", ba1);
try {
HttpClient httpclient = new DefaultHttpClient(p);
HttpPost res=new HttpPost(result);
HttpResponse response = httpclient.execute(res);
HttpEntity entity = response.getEntity();
i1 = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(i1,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
if (reader.readLine() == null) {
Log.e("inside if","No data");
} else {
String line = reader.readLine();
i1.close();
back=sb.toString();
}
我沒有收到任何錯誤或異常。
問題是我沒有存儲圖像作爲file.I我只是捕捉圖像,並顯示在imageview..Can我發送作爲多實體文件??? – 2012-08-08 06:04:28
這個MULTIPARTENTITY工作正常。你甚至可以通過multipartEntity將文件直接發送到服務器。我想再補充一點,如果你想發送字節到服務器,只需要將它轉換成Base64字符串並通過參數發送給服務器。 – 2012-08-31 06:42:42