0
我使用此代碼,我發現在一些頁面,但我只能從我的Android應用程序上傳圖像到服務器,並正在工作,但是當我上傳一個視頻(.mp4)它保存爲「文件」像未知。如何使用多部分郵政實體上傳視頻?
public void upload() throws Exception {
//Url of the server
String url = "";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
MultipartEntity mpEntity = new MultipartEntity();
//Path of the file to be uploaded
String filepath = "";
File file = new File(filepath);
ContentBody cbFile = new FileBody(file);
//Add the data to the multipart entity
mpEntity.addPart("image", cbFile);
mpEntity.addPart("name", new StringBody("Test", Charset.forName("UTF-8")));
mpEntity.addPart("data", new StringBody("This is test report", Charset.forName("UTF-8")));
post.setEntity(mpEntity);
//Execute the post request
HttpResponse response1 = client.execute(post);
//Get the response from the server
HttpEntity resEntity = response1.getEntity();
String Response=EntityUtils.toString(resEntity);
Log.d("Response:", Response);
//Generate the array from the response
JSONArray jsonarray = new JSONArray("["+Response+"]");
JSONObject jsonobject = jsonarray.getJSONObject(0);
//Get the result variables from response
String result = (jsonobject.getString("result"));
String msg = (jsonobject.getString("msg"));
//Close the connection
client.getConnectionManager().shutdown();
}
有什麼辦法可以使這項工作上傳視頻嗎?
請用代碼更新您的答案。 – user2251725 2013-07-25 13:19:48
可以請你發佈你的最終解決方案,因爲在http實體上沒有setChunk方法 – Ravi 2013-09-18 08:47:05