如何从Android向PHP服务器上传视频
嗨,伙计们,我正在使用下面的代码,但是得到了错误0作为响应。请在以下代码中提供帮助,因为我即将成功如何从Android向PHP服务器上传视频,php,android,Php,Android,嗨,伙计们,我正在使用下面的代码,但是得到了错误0作为响应。请在以下代码中提供帮助,因为我即将成功 public void video() { File file = new File(exsistingFileName); try { HttpClient client = new DefaultHttpClient(); String postURL = "http://10.0.0.27/sportscloud/devices/upl
public void video()
{
File file = new File(exsistingFileName);
try {
HttpClient client = new DefaultHttpClient();
String postURL = "http://10.0.0.27/sportscloud/devices/uploadBlogData.php";
HttpPost post = new HttpPost(postURL);
FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("email", new StringBody("test1@nga.com", "text/plain", Charset.forName( "UTF-8")));
reqEntity.addPart("gameId", new StringBody("1024", "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);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
}您会遇到什么样的错误?更多信息将提供帮助:)
试试这个
InputStream is = this.getAssets().open(exsistingFileName);
byte[] data = IOUtils.toByteArray(is);
InputStreamBody isb = new InputStreamBody(new ByteArrayInputStream(data),"uploadedFile");
reqEntity.addPart("uploadfile",isb);
祝你好运