-5 works

Upload multiple images to a REST API


dashboard

Posted by @bassel #dart #flutter

final imagesBytes = {};
for (Asset a in images) {
  final bytes = await a.requestOriginal();
  imagesBytes[a.identifier] = bytes.buffer.asUint8List();
}
final imagesData = images.map((a) => UploadFileInfo.fromBytes(imagesBytes[a.identifier], a.name)).toList();
final response = await Dio().post('myapi/uploadImage.php',
  data: FormData.from({
    'images[]': imagesData,
}));
content_copy

This snippet of code uses the flutter packages [multi_image_picker](https://pub.flutter-io.cn/packages/multi_image_picker) and [dio](https://pub.flutter-io.cn/packages/dio) to upload multiple images to a REST API. Important note: please make sure to add `[]` to the key of the list of images.


>> Browse more code snippets

more_vert