我想将视频从android上传到php服务器。视频只上传一个手机。如果我从其他手机上传视频意味着视频无法上传。如何从所有手机上传视频 这是我的编码。
class UploadTask extends AsyncTask<String, Void, String> {
String sResponse = null;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pd.setMessage("loading");
pd.show();
}
@Override
protected String doInBackground(String... params) {
try {
String url =Serviceurl.url + "video";
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
int i=0;
File sourceFile = new File(selectedPath);
entity.addPart("video", new FileBody(sourceFile));
entity.addPart("user_id", new StringBody("66"));
httpPost.setEntity(entity);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
entity.writeTo(bytes);
String content = bytes.toString();
String content1 = entity.toString();
Log.e("MultiPartEntityRequest:",content);
Log.e("MultiPartEntity---11:",content1);
HttpResponse response = httpClient.execute(httpPost,
localContext);
sResponse = EntityUtils.getContentCharSet(response.getEntity());
System.out.println("sResponse : " + sResponse);
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage(), e);
}
return sResponse;
}
@Override
protected void onPostExecute(String sResponse) {
try {
pd.dismiss();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
}
}