基于标准http实现Android多文件上传

时间:2021-05-19

实现多文件的上传,基于标准的http来实现。

1.多文件上传MyUploader类的实现:

/** * * 同步上传多个文件 * 基于标准的http实现,需要在非UI线程中调用,以免阻塞UI。 * */public class MyUploader { private static final String TAG = "MyUploader"; // ////////////////////同步上传多个文件///////// /** * 同步上传File * * @param Url * @param fullFileName * : 全路径,ex. /sdcard/f/yh.jpg * @param fileName * : file name, ex. yh.jpg * @return 服务器的响应结果(字符串形式) */ public String MyUploadMultiFileSync(String Url, List<String> fileList, Map<String, String> params) { String reulstCode = ""; String end = "\r\n"; String twoHyphens = "--"; String boundary = "--------boundary"; try { URL url = new URL(actionUrl); HttpURLConnection con = (HttpURLConnection) url.openConnection(); // 允许Input、Output,不使用Cache con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); // 设置传送的method=POST con.setRequestMethod("POST"); // setRequestProperty con.setRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Charset", "UTF-8"); // con.setRequestProperty("Content-Type", // "application/x-/ranke/HttpAsyncTest

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章