I want to pick multiple images from gallery and upload them via Flutter Dio Package
1 Answer
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;
}
1 Comment
Milan R Dhameliya
I want to upload multiple images...... not single image