从上传的Andr​​oid图像到PHP服务器 [英] Uploading an image from android to a PHP server

查看:112
本文介绍了从上传的Andr​​oid图像到PHP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用MultiPartEntity从机器人到PHP服务器上传一张图片,但我有麻烦找出问题的根源,进度对话框钢铁下载,而不提供任何这里我回应code:

I'm trying to upload an image from android to a PHP server by using MultiPartEntity but i have trouble to find the source of the problem , the progress dialog steel downloading without providing any response here my code :

    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;)

i don't know where's the problem !! many thanks befor ;)

推荐答案

问题解决了,那是因为我小的互联网连接,我现在尽量限制在模拟器生成与SocketTimeoutException如果连接时间,但遗憾的是没有我的手机宏碁Liquid!

problem solved, it was because of my low internet connection, now I try to limit the connection time with SocketTimeoutException that is generated in the emulator, but unfortunately not in my phone acer liquid!

这篇关于从上传的Andr​​oid图像到PHP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆