android 上传图片
来源:互联网 发布:grub2手动引导ubuntu 编辑:程序博客网 时间:2024/05/01 07:43
public static String uploadPicture(String url, String uploadFile) {
String resultcode = "1";// 0表示成功 ,1表示失败
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost(url);
File file = new File(uploadFile); // DEBUG
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/jpg");
ContentBody cbMessage;
try {
cbMessage = new StringBody("TEST TSET");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.getMessage();
}
ContentBody cbAccessToken;
try {
cbAccessToken = new StringBody("sfsdfsdf");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.getMessage();
}
mpEntity.addPart("source", cbFile);// 上传文件
// mpEntity.addPart("message", cbMessage);// 上传信息
// mpEntity.addPart("access_token", cbAccessToken);// 上传信息
httppost.setEntity(mpEntity); // DEBUG
HttpResponse response;
try {
response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.getMessage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.getMessage();
}
HttpEntity resEntity = response.getEntity(); // DEBUG
if (resEntity != null) {
try {
if (EntityUtils.toString(resEntity) == "1") {
resultcode = "0";
}
} catch (org.apache.http.ParseException e) {
e.printStackTrace();
return e.getMessage();
} catch (IOException e) {
e.printStackTrace();
return e.getMessage();
}
}
httpclient.getConnectionManager().shutdown();
return resultcode;
}
String resultcode = "1";// 0表示成功 ,1表示失败
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost(url);
File file = new File(uploadFile); // DEBUG
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/jpg");
ContentBody cbMessage;
try {
cbMessage = new StringBody("TEST TSET");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.getMessage();
}
ContentBody cbAccessToken;
try {
cbAccessToken = new StringBody("sfsdfsdf");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.getMessage();
}
mpEntity.addPart("source", cbFile);// 上传文件
// mpEntity.addPart("message", cbMessage);// 上传信息
// mpEntity.addPart("access_token", cbAccessToken);// 上传信息
httppost.setEntity(mpEntity); // DEBUG
HttpResponse response;
try {
response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.getMessage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.getMessage();
}
HttpEntity resEntity = response.getEntity(); // DEBUG
if (resEntity != null) {
try {
if (EntityUtils.toString(resEntity) == "1") {
resultcode = "0";
}
} catch (org.apache.http.ParseException e) {
e.printStackTrace();
return e.getMessage();
} catch (IOException e) {
e.printStackTrace();
return e.getMessage();
}
}
httpclient.getConnectionManager().shutdown();
return resultcode;
}
- Android 选择图片、上传图片
- Android URL上传图片
- android HttpClient 上传图片
- android HttpClient 上传图片
- android图片上传
- android图片上传服务器
- android上传图片
- android 上传图片
- android图片压缩上传
- Android 图片压缩上传
- Android 上传图片
- Android Base64上传图片
- Android 上传文件,图片
- android图片上传
- android图片上传
- android 上传图片
- Android 上传/下载图片
- Android图片上传
- sqlserver脚本时间计算
- Android:异步调用详解
- 怎样才能检测到链表中循环
- 装机工具软件收藏
- I2C协议指东
- android 上传图片
- UITableView分割线样式与颜色
- 【记录】cygwin下折腾个人配置环境
- 用C语言获取任意文件的长度(可能大于2GB)
- Flex中的Bindable的用法
- 为IEnumerable接口添加增删查等操作
- 以log(n)的时间求矩形内的点
- 关于HASH和MD5
- lazarus连接access数据库