Multiple Image Upload Using Multipart In Flutter

Multiple Image Upload Using Multipart In Flutter :

Multiple Image Upload Using Multipart In Flutter

1) Multiple image upload in flutter.
2) Multipart image upload in flutter.

Future uploadmultipleimage(List images) async {
  var uri = Uri.parse("");

  http.MultipartRequest request = new http.MultipartRequest('POST', uri);
  request.headers[''] = '';

  request.fields['user_id'] = '10';
  request.fields['post_details'] = 'dfsfdsfsd';
  //multipartFile = new http.MultipartFile("imagefile", stream, length, filename: basename(imageFile.path));

  List<MultipartFile> newList = new List<MultipartFile>();

  for (int i = 0; i < images.length; i++) {
    File imageFile = File(images[i].toString());
    var stream =
        new http.ByteStream(DelegatingStream.typed(imageFile.openRead()));
    var length = await imageFile.length();
    var multipartFile = new http.MultipartFile("imagefile", stream, length,
        filename: basename(imageFile.path));
    newList.add(multipartFile);
  }

  request.files.addAll(newList);
  var response = await request.send();

  if (response.statusCode == 200) {
    print("Image Uploaded");
  } else {
    print("Upload Failed");
  }
  response.stream.transform(utf8.decoder).listen((value) {
    print(value);
  });
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in