实现多文件的上传,基于标准的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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。