我无法将图像上传到 rest api 我已经检查了 api 它的工作正常。
我无法将文件(图像)转换为可上传的表格,有人可以帮我吗?我已经运行了 flutter doctor -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);
}
}
错误日志如下:
I/flutter (22523):DioError [DioErrorType.RESPONSE]:Http 状态错误 [500] I/flutter (22523):DioError [DioErrorType.RESPONSE]:Http 状态错误 [500]
状态错误是:
I/flutter (22523):DioError [DioErrorType.RESPONSE]:Http 状态错误 [500]
我搜索了这个错误但没有找到任何解决方案,有人可以帮助我吗?