android 上传文件图片
方法一,自己构造multiparty 等各种参数 文件和参数同时上传参考第二条回答
参考:http://stackoverflow.com/questions/4966910/androidhow-to-upload-mp3-file-to-http-server/5176670#5176670
http://stunningco.de/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/
文件加参数:
http://www.beyondcompare.cn/android-shang-chuan-wen-jian-he-can-shu-dao-web-fu-wu-qi-php-jie-shou-bing-bao-cun-php.html
方法二:使用MultipartyEntityBuilder
MultipartyEntity过时 使用MulipartyEntityBuilder
参考:http://stackoverflow.com/a/22803149/4697356
http://stackoverflow.com/questions/2017414/post-multipart-request-with-android-sdk/22803149#22803149
带上传进度条上传
http://stackoverflow.com/questions/18964288/upload-a-file-through-an-http-form-via-multipartentitybuilder-with-a-progress/19188010#19188010
方法三: 或使用volley android-async-http retrofit等开源库
android-async-http中文手册
http://20142014.iteye.com/blog/2010705
附:
最简单的方式:
http://stackoverflow.com/questions/15968165/uploading-files-and-other-data-from-android-through-http-post-request
http://stackoverflow.com/questions/4126625/how-to-send-a-file-in-android-from-mobile-to-server-using-http
Easy, you can use a Post request and submit your file as binary (byte array).
String url = "http://yourserver";
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),
"yourfile");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
//Do something with response...
} catch (Exception e) {
// show error
}
参考:http://www.coderzheaven.com/2011/04/25/android-upload-an-image-to-a-server/
http://stunningco.de/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/
http://stackoverflow.com/questions/2017414/post-multipart-request-with-android-sdk
浙公网安备 33010602011771号