android JSON 上传图片和视频到服务器
//上传采集数据到服务器
private void UploadData(final String filename){
new Thread() {
public void run() {
try {
HttpPost httpRequestHttpPost = new HttpPost(HttpUtils.urlpath + "getCollectInfo");
MultipartEntity multipartEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE,
null, Charset.forName(HTTP.UTF_8));
ContentBody contentBody = new FileBody(new File(filename));
multipartEntity.addPart("uploadedfile",contentBody);
multipartEntity.addPart("uid", new StringBody(settings.getInt("user_id", 0)+"",Charset.forName("UTF-8")));
multipartEntity.addPart("node_id", new StringBody(current_node_id,Charset.forName("UTF-8")));
multipartEntity.addPart("info", new StringBody(et_remark.getText().toString(),Charset.forName("UTF-8")));
multipartEntity.addPart("createtime", new StringBody(getTime(),Charset.forName("UTF-8")));
//把要传输的内容放到请求里面
httpRequestHttpPost.setEntity(multipartEntity);
//创建客户端对象
HttpClient httpClient = new DefaultHttpClient();
//执行请求并得到返回结果
HttpResponse httpResponse = httpClient.execute(httpRequestHttpPost);
String ID = EntityUtils.toString(httpResponse.getEntity());
JSONObject json = new JSONObject(ID);
int code = json.getInt("code");
if(code==0){
isupload=true;//上传成功标志
}
System.out.println("uploadpicture========code"+code);
} catch (IOException e) {
System.out.println("IOException========wrong");
e.printStackTrace();
} catch (JSONException e) {
System.out.println("JSONException========wrong");
e.printStackTrace();
}
};
}.start();
}
UploadData("/sdcard/HUA_video/20160316102418.jpg");//图片路径
UploadData("/sdcard/HUA_video/20160316102418.mp4");//视频路径
上面是我上传数据的代码,然后参数是我要上传的路径文件,但是发现图片是可以正常上传的,但是视频出现了System.out.println("IOException========wrong");的情况,麻烦各位帮我看看,小白一个,求大家帮帮忙