【发布时间】:2023-02-23 00:00:48
【问题描述】:
我正在尝试将带有文件的 dio 表单数据发送到 api,但出现此错误。
Dio dio = Dio(
BaseOptions(
baseUrl: baseUrl,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ${APIVariables.token}',
},
),
);
FormData formData = FormData.fromMap({
"id": complaint.id,
"title": complaint.title,
"description": complaint.description,
"complainedPosition": complaint.complainedPosition,
"deptId": complaint.departmentId,
"typeId": complaint.typeId,
"priortyId": complaint.priorityId,
"files": complaint.files
.map((file) async => await MultipartFile.fromFile(file.path,
filename: basename(file.path)))
.toList(),
});
Response response = await dio.post(
'Complaint',
data: formData,
),
如何以正确的方式发送带有选项的文件并显示具有上传百分比的进度,并在完成后得到响应?
【问题讨论】:
-
状态代码 415 表示服务器端不接受您发送的文件格式,即“application/json”。你能检查一下服务器期望的正确格式是什么吗?
-
这种类型来自 api:媒体类型 application/json Controls Accept 标头。