I want to pick multiple images from gallery and upload them via Flutter Dio Package
Asked
Active
Viewed 102 times
1 Answers
1
To pick images from the library use a package from pub.dev. For example multi_image_picker for example.
The question of uploading multiple images to Dio is a duplicate. But here is the suggested solution in the linked article:
Future<Response<dynamic>> uploadImages(List<Asset> images, String url) async {
List<MultipartFile> multipartImageList = new List<MultipartFile>();
for (Asset asset in images) {
ByteData byteData = await asset.getByteData();
List<int> imageData = byteData.buffer.asUint8List();
MultipartFile multipartFile = new MultipartFile.fromBytes(
imageData,
filename: 'load_image',
contentType: MediaType("image", "jpg"),
);
multipartImageList.add(multipartFile);
}
FormData formData = FormData.fromMap({
"multipartFiles": multipartImageList,
"userId": '1'
});
Dio dio = new Dio();
var response = await dio.post(url, data: formData);
return response;
}

Lulupointu
- 3,364
- 1
- 12
- 28
-
I want to upload multiple images...... not single image – Milan R Dhameliya Oct 23 '20 at 04:36