Я использую https://github.com/esafirm/android-image-picker эту библиотеку для получения списка изображений
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.upload_btn:
openImagesList();
break;
}
}
public void openImagesList() {
ImagePicker.create(this) // Activity or Fragment
.start();
}
@Override
public void onActivityResult(int requestCode, final int resultCode, Intent data) {
if (ImagePicker.shouldHandle(requestCode, resultCode, data)) {
// Get a list of picked images
List<Image> images = ImagePicker.getImages(data);
List<File> imgFile = new ArrayList<>();
for (Image imge : images) {
imgFile.add(new File(imge.getPath()));
}
for (File f : imgFile) {
if (f.exists()) {
Log.i(TAG, "exist");
}
}
uploadToSever(imgFile);
}
super.onActivityResult(requestCode, resultCode, data);
}
Использование https://github.com/amitshekhariitbhu/Fast-Android-Networking для запроса POST
public void uploadToSever(List<File> imgList) {
AndroidNetworking.upload("your sever url")
.addMultipartFileList("image[]", imgList)
.addMultipartParameter("key", "value")
.setPriority(Priority.HIGH)
.build()
.setUploadProgressListener(new UploadProgressListener() {
@Override
public void onProgress(long bytesUploaded, long totalBytes) {
// do anything with progress
}
})
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
// do anything with response
}
@Override
public void onError(ANError error) {
// handle error
}
});
}