开发者

Android Video Upload to Php server?

How to upload the video or image file to php server.Anyone provide some sample app or s开发者_开发技巧ource to upload the file in php server please.


I'd suggest creating an AsyncTask to handle your upload and then use the Apache Libs to do a POST to your server. I have a system in place now that posts images to a Linux server and then PHP accepts the POST and saves the image data. Try something like this, you'll need to get the commons-io jar and the httpmime jar from Apache if I remember correctly.

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;

HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://www.mywebserver.com/upload");

MultipartEntity multipart = new MultipartEntity();
multipart.addPart("photo",bitmapdata);

postRequest.setEntity(multipart);
HttpResponse response = httpClient.execute(postRequest);

InputStream content = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
StringBuilder serverMsg = new StringBuilder();
String line = "";
while((line = reader.readLine()) != null){ serverMsg.append(line + "\n"); }
content.close();

Then over in PHP, check for the POST and save the image using whatever library or code you prefer. I'm sure you could easily adjust this code to send video data instead of a photo.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜