2010-09-26 129 views
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;)

+0

它工作时,我删除文件transfert部分,是文件声明正确?请帮帮我 !! – 2010-09-27 17:16:38

回答

1

问题解决了,这是因为我的低互联网连接,现在我尝试限制连接时间与模拟器中生成的SocketTimeoutException,但不幸在我的手机acer液体!

相关问题