How to post list dynamic file to server in flutter

Viewed 24

I want to post data dynamic with file then debug in server, I see content of description, but file always is null. This is my code

Map<String, dynamic> params = {
        'folder': 'APP365',
        'createAt': DateTime.now().toString(),
        'files': listFiles!.map((item) => {'file': MultipartFile.fromFileSync(item.path ?? "", filename: item.path.split('/').last), 'description': '....'}),
      };
      final response = await Dio().post(
        '....',
        data: FormData.fromMap(params),
        options: Options(
          headers: {
            'Content-Type': 'multipart/form-data',
          },
        ),
      );

in there listFiles is List<File>

Please help me, thank you so much!

0 Answers
Related