我收到ClientException (内容大小超过指定的 contentLength。在预期 5965 时写入了 10911 字节。尝试将 m4a 文件上传到我的服务器时出错。我尝试从邮递员发送完全相同的请求,它工作得很好。我也能够在flutter中使用完全相同的请求发送imgs和视频。我跟踪了发送方法,它在框架中的Client类中的方法“发送”中给出了错误,这是我的请求代码:
static Future<String> uploadFile(
{Attachment attachment,
List<Attachment> attachments,
String toUserIdForMessage}) async {
Uri _uri = Uri.parse(globalUrl + file + 'Uploads');
http.MultipartRequest _reqss = http.MultipartRequest(
'POST',
_uri,
);
Attachment _attForHeaders = attachment ?? attachments[0];
_reqss.headers.addAll(await headersWToken);
_reqss.fields['ownerType'] =
_attForHeaders.attachmentOwner.index.toString();
_reqss.fields['ownerId'] = _attForHeaders.ownerId.toString();
_reqss.fields['toUserIdForMessage'] = toUserIdForMessage;
if (attachment != null && attachment.path != null)
_reqss.files.add(
await http.MultipartFile.fromPath(
attachment.path,
attachment.path,
),
);
if (attachments != null && attachments.length != 0) {
for (Attachment att in attachments) {
_reqss.files.add(
await http.MultipartFile.fromPath(
att.path,
att.path,
),
);
}
}
var _response = await (_reqss.send());
var _re = _response.stream.bytesToString();
return _re;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3554 次 |
| 最近记录: |