【发布时间】:2021-03-27 00:20:30
【问题描述】:
我是 Flutter 的新手,想了解如何在 Flutter 中使用 Dio 进行多部分发布请求。场景是,在我的应用程序中,我希望允许用户使用多部分发布请求提交他/她的个人资料详细信息和个人资料图片。我正在尝试下面的代码。请在此代码中提供任何其他改进。
try{
String filename = _image.path.split("/").last;
FormData formData = new FormData.fromMap({
"visitor_photo": await MultipartFile.fromFile(_image.path,filename: filename, contentType: new MediaType('image','png')),
"type": "image/png"
});
Response response =
await dio.post(url,data: formData,options: Options(
headers: {
"accept": "*/*",
"Authorization": "Bearer 0rwQmHeADz6g",
"Content-Type" : "multipart/form-data"
}
));
}catch(e){
print(e);
}
【问题讨论】:
标签: android-studio flutter dart flutter-dependencies dio