我知道我可以从 AsyncHttpClient 上传单个文件
http://loopj.com/android-async-http/ http://loopj.com/android-async-http/
File myFile = new File("/path/to/file.png");
RequestParams params = new RequestParams();
try {
params.put("profile_picture", myFile);
} catch(FileNotFoundException e) {}
但我必须使用多部分帖子将多个文件上传到服务器。
我怎样才能做到这一点?
您可以传递文件数组作为 files 键的值。
为此,请按照以下代码操作:
File[] myFiles = { new File("pic.jpg"), new File("pic1.jpg") };
RequestParams params = new RequestParams();
try {
params.put("profile_picture[]", myFiles);
} catch(FileNotFoundException e) {
}
另外,如果你想要一个动态数组,你可以使用ArrayList
并使用 .toArray() 方法转换为 File[] 类型
ArrayList<File> fileArrayList = new ArrayList<>();
//...add File objects to fileArrayList
File[] files = new File[fileArrayList.size()];
fileArrayList.toArray(files);
希望这有帮助。 =D
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)