I am trying to send a list of images using the MultipartFile, the sending is done according to the id and the key of each image ...
the problem, I am told that: Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'int'
But it's not clear since I don't use any int in my songs ...
Here's my code:
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);
}
}
}
The API Doc:
// 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
},