我一直在尝试将多个图像/文件上传到 Flutter 的后端。我正在使用Dio
. 到目前为止,我还不能这样做。
我已经能够使用邮递员做到这一点。这是表单数据
这是我的代码:
Future<dynamic> fileUpload(List<String> filepath, String url) async {
var token = await storage.getToken();
var idToken = await storage.getIdToken();
Dio dio = Dio();
List uploadList = [];
for (var file in filepath) {
var multipartFile = await MultipartFile.fromFile(
file
);
uploadList.add(multipartFile);
}
FormData formData = FormData.fromMap({"assignment": uploadList});
var response = await dio.post(APIURL.baseUrl + url,
data: formData,
options: Options(headers: {
HttpHeaders.authorizationHeader: "Bearer $token",
'idToken': idToken,
}));
return response;
}
有人可以帮忙吗。