Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 我无法在Flatter中使用DIO包将图像和表单数据上传到RESTAPI_Flutter_Dart_Dio - Fatal编程技术网

Flutter 我无法在Flatter中使用DIO包将图像和表单数据上传到RESTAPI

Flutter 我无法在Flatter中使用DIO包将图像和表单数据上传到RESTAPI,flutter,dart,dio,Flutter,Dart,Dio,我不能上传图片到RESTAPI在颤振我已经检查了api的工作良好 我无法将文件(图像)转换为可上传的形式,有人能帮我吗? 我已经跑了颤振博士-v一切都很好:) 以下是我用来发布表单数据的代码: Future<void> uploadAccountDetails(AccountDetailsModel details) async { var url = baseUrl + '/api/uploads/images'; try { Dio dio = new

我不能上传图片到RESTAPI在颤振我已经检查了api的工作良好

我无法将文件(图像)转换为可上传的形式,有人能帮我吗? 我已经跑了颤振博士-v一切都很好:) 以下是我用来发布表单数据的代码:

Future<void> uploadAccountDetails(AccountDetailsModel details) async {
    var url = baseUrl + '/api/uploads/images';
    try {
      Dio dio = new Dio();
      FormData formData = new FormData.fromMap(
        {
          'city': details.cityName,
          'country': details.countryName,
          'residence_address': details.address,
          'dob': details.dob,
          'id_num': details.id,
          'passport_num': details.passportNo,
          'driving_license_nim': details.drivingLicNo,
          'user_id': 162,
          'postal_code': details.postalCode,
          'id_pic': await MultipartFile.fromFile(details.idPic.path,
              filename: basename(details.idPic.path)),
          'driving_license_pic':
              await MultipartFile.fromFile(details.drivingLicPic.path,
                  filename: basename(
                    details.drivingLicPic.path,
                  )), 
          'birth_certificate': await MultipartFile.fromFile(
            details.drivingLicPic.path,
            filename: basename(details.birthCertPic.path),
          ),
          'residence_permit_pic': await MultipartFile.fromFile(
            details.resPermitPic.path,
            filename: basename(details.resPermitPic.path),
          ),
          'profile_pic': await MultipartFile.fromFile(details.profilePic.path,
              filename: basename(details.profilePic.path)),
        },
      );
      print(formData);
      Response response = await dio.post(
        url,
        data: formData,
        onSendProgress: (received, total) {
          if (total != -1) {
            print((received / total * 100).toStringAsFixed(0) + "%");
          }
        },
      );
      print(response.statusCode);
      // print(response);

    } catch (e) {
      print(e);
      throw (e);
    }
  }
Future uploadAccountDetails(AccountDetails模型详细信息)异步{
var url=baseUrl+'/api/uploads/images';
试一试{
Dio Dio=新的Dio();
FormData FormData=新建FormData.fromMap(
{
“城市”:details.cityName,
“国家”:详细信息。国家名称,
“居住地址”:details.address,
“dob”:details.dob,
'id_num':details.id,
“passport_num”:详细信息。passportNo,
“驾驶执照”:详细信息。驾驶执照,
“用户id”:162,
“邮政编码”:details.postalCode,
“id_pic”:等待MultipartFile.fromFile(details.idPic.path,
文件名:basename(details.idPic.path)),
“驾驶执照”图片:
等待MultipartFile.fromFile(details.drivingLicPic.path,
文件名:basename(
details.drivingLicPic.path,
)), 
“出生证书”:等待MultipartFile.fromFile(
details.drivingLicPic.path,
filename:basename(details.birthCertPic.path),
),
“居住许可证”:等待MultipartFile.fromFile(
details.resPermitPic.path,
filename:basename(details.resPermitPic.path),
),
“profile_pic”:等待MultipartFile.fromFile(details.profilePic.path,
文件名:basename(details.profilePic.path)),
},
);
打印(表格数据);
响应=等待dio.post(
网址,
数据:formData,
onSendProgress:(已收到,总计){
如果(总计!=-1){
打印((已接收/总计*100)。ToStringGasFixed(0)+“%”);
}
},
);
打印(响应状态码);
//打印(回复);
}捕获(e){
印刷品(e);
投掷(e);
}
}
错误日志如下所示:

I/flatter(22523):DioError[DioErrorType.RESPONSE]:Http状态错误 [500]I/颤振(22523):DioError[DioErrorType.RESPONSE]:Http状态 错误[500]

状态错误为:

I/flatter(22523):DioError[DioErrorType.RESPONSE]:Http状态错误 [500]


我搜索了这个错误,但没有找到任何解决方案,有人能帮我吗?

我用dio发布了一个包含其他信息的文件路径:

  Dio dio = new Dio();
  FormData formData = new FormData();
  formData.add(
  "apiKey",
  "my_api_key",
  );
  formData.add(
  "file",
  "image_path",
  );
 Response response = await dio.post(
"https://localhost",
data: formData,
onSendProgress: (int sent, int total) {
  // do something
},
).catchError((onError) {
 throw Exception('something');
});

你在尝试什么应用程序?邮递员?失眠?我正在使用postman测试我的API。我正在使用的Dio包中没有Formdata对象的方法。您使用的是哪个版本的Dio?