【问题标题】:Could not upload image with Dio无法使用 Dio 上传图像
【发布时间】:2020-10-14 05:55:09
【问题描述】:

我正在使用Dio 将图像上传到后端。它经常给我Reference not set 响应和500 错误代码。我尝试从另一个来源上传,它似乎正在工作。这段代码有什么问题?

performPostRequestWithToken() 的代码还没有写,因为其他方法也在使用它,而且它似乎工作正常。

Future<UserModel> submitProfileImage(String imagePath) async {
 if (isEmpty(imagePath)) throw Exception("NULL image found");
 final formdata = FormData.fromMap({
   "profilePic": await MultipartFile.fromFile(
     imagePath,
     filename: "profilePic.png",
   ),
 });
 final usertoken = await getCurrentUserToken();
 print(usertoken);
 final response = await _dioHttpService.performPostRequestWithToken(
   "/User/UploadImage",
   formdata,
   usertoken,
 );
 if (response.statusCode >= 200 && response.statusCode < 300) {
   return UserModel.fromMap(response.data["data"]);
 } else {
   throw Exception(response.statusMessage);
 }
}

【问题讨论】:

    标签: flutter flutter-dependencies dio


    【解决方案1】:

    我的问题是映射键 profilePic 导致了问题。这绝对是后端的问题,因为他们期望密钥是file。 改变了它,一切都解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-29
      • 2020-10-20
      • 2021-08-17
      • 1970-01-01
      • 2023-03-23
      • 2019-08-30
      • 1970-01-01
      • 2020-12-27
      相关资源
      最近更新 更多