0

I want to pick multiple images from gallery and upload them via Flutter Dio Package

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I want to upload multiple images...... not single image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.