to upload video to a php server through android
This is what I am doing to upload a video to a server:
email gameId source uploadedfile
are the parameters that have to be sent. email
, gameId
and source
are string values,
whereas uploadedfile
is the filebody to be uploaded.
Running this code gives response error0
.
HttpClient client = new 开发者_运维知识库DefaultHttpClient();
String postURL = GlobalConfig.url+"uploadBlogData.php";
HttpPost post = new HttpPost(postURL);
FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("email", new StringBody(GlobalConfig.pref.getString(GlobalConfig.KEY_User_Emailid,""), "text/plain", Charset.forName( "UTF-8")));
reqEntity.addPart("gameId", new StringBody(GlobalConfig.pref.getString(
GlobalConfig.KEY_Game_Created_id,
""), "text/plain", Charset.forName( "UTF-8")));
reqEntity.addPart("source", new StringBody("phone", "text/plain", Charset.forName("UTF-8")));
reqEntity.addPart("uploadfile", bin);
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
Log.d("resP",GlobalConfig.getStringFromResponse(response));
HttpEntity resEntity = response.getEntity();
精彩评论