1
我想通過使用MultiPartEntity將圖像從android上傳到PHP服務器,但我無法找到問題的來源,進度對話框鋼下載沒有提供任何響應這裏我的代碼:將圖像從Android上傳到PHP服務器
public String postFunction(String s_v1, String s_v2, String s_v3)
throws ParseException, ClientProtocolException, IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(s_v1);
//required apache-mime4j-0.6, et httpmime-4.0.3
MultipartEntity mp = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mp.addPart("choix", new StringBody("2"));
boolean exists = (new File("/data/data/my.package/files/avatar.jpg")).exists();
if (!exists){
Log.i(TAG,"no file");
}
else
{
File tempImg = new File("/data/data/my.package/files/avatar.jpg");
FileBody bin = new FileBody(tempImg, "image/jpg");
mp.addPart("photo_r", bin);
}
mp.addPart("myString1", new StringBody(s_v2, Charset.forName("UTF-8")));
mp.addPart("myString2", new StringBody(s_v3, Charset.forName("UTF-8")));
httppost.setEntity(mp);
Log.i(TAG,"start ");
HttpResponse response = httpclient.execute(httppost);
Log.i(TAG,"end");
return response;
}
我不知道問題在哪裏!! 非常感謝befor;)
它工作時,我刪除文件transfert部分,是文件聲明正確?請幫幫我 !! – 2010-09-27 17:16:38