在 flutter 中使用 MultipartFile 发送许多带有 id foreach item 的图像

问题描述

我正在尝试使用 multipartfile 发送图像列表,发送是根据每个图像的 id 和键完成的...

问题,有人告诉我: 未处理的异常:类型“_InternalLinkedHashMap”不是“int”类型的子类型

但不清楚,因为我的歌曲中没有使用任何 int ...

这是我的代码

sendPostimages(List responseImages,List userImages) async {
final _path = "files/send";
final uri = Uri.https("$myImgPath",_path);

final imageUploadRequest = http.MultipartRequest('POST',uri);

List imgs = [];
var filePostImg;

for (final item in responseImages) {
  imgs.add({
    ...responseImages[item],"name": "f$item",});
  filePostImg =
      await http.multipartfile.fromPath("f$item",userImages[item].path);
  final listPostImgs =
      await http.multipartfile.fromPath("files",imgs.toString());
  imageUploadRequest.files.add(filePostImg);
  imageUploadRequest.files.add(listPostImgs);

  try {
    final streamedResponse = await imageUploadRequest.send();
    final response = await http.Response.fromStream(streamedResponse);
    if (response.statusCode != 200) {
      final Map<String,dynamic> responseData = jsonDecode(response.body);
      print('''
    

    erreur de l'envoi des images...


    $responseData
    
    
    ''');
    }
    final Map<String,dynamic> responseData = jsonDecode(response.body);
    print(
      '''
    
    
    $responseData 
    
    
    ''',);
  } catch (e) {
    print(e);
  }
}

}

API 文档:

// When sending several files
    "files": ["Object[]",[
        // For each file
        {
            "fid": "String","fkey": "String","name": "String" // Custom name that you choose
        }
    ]],// For each file
    "f01": "File" // The field's name must be the same as in the "files" object
},

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)