java如何在安卓中将文件上传到服务器?
如何使用volley library从移动设备向服务器发送文件(数据)
下面我列出了我的参数,请帮我解决这个问题
Map<String, String> mHeaderPart= new HashMap<>();
mHeaderPart.put("Content-type", "multipart/form-data;");
mHeaderPart.put("Authorization", authorizationKey);
//String part
Map<String, String> mStringPart= new HashMap<>();
mStringPart.put("candidate_id", SessionStores.getBullHornId(getActivity()));
mStringPart.put("externalID", "portpolio");
mStringPart.put("fileCount", "2");//number of files
mStringPart.put("fileType", "SAMPLE");
mStringPart.put("platform", "安卓");
//file param
Map<String, File> mFilePartData= new HashMap<>();
在上面的文件参数中,我必须添加n个文件并将其发送到服务器。我如何从设备中获取文件,并使用param添加n个文件,并将其发送到服务器。如果有人可以,请给我建议
如果有人有使用截击发送多个文件的例子,请指导我。提前谢谢
# 1 楼答案
Volly不提供在服务器上使用multi-part上传文件的直接方式
要使用volly上传多个文件,请执行以下步骤:
步骤1:创建一个名为MultipartRequest的新类。从volly扩展请求的java,如下所示:
第二步:
从你的活动中:
第3步:在应用程序构建中。gradle文件添加:
注:来自API 22组织。阿帕奇。http。HttpEntity已被弃用,因此最好使用URLConnection或改型库,两者都有各自的优点和缺点