flutter - ClientException(内容大小超过指定的 contentLength。10911 字节写入而预期 5965
问题描述
我收到ClientException(内容大小超过指定的contentLength。10911字节写入而预期5965。尝试将m4a文件上传到我的服务器时出错。我试图从邮递员发送完全相同的请求,它工作得很好。我也能够在颤振中使用完全相同的请求发送 imgs 和视频。我跟踪了 send 方法,它在框架中的 Client 类中的方法“send”中给出了错误,这是我的请求代码:
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;
}
解决方案
当我尝试录制语音消息并上传时发生此错误。问题是关于不关闭录音机。所以当请求正在准备时,记录器继续记录,因此出现了大小差异问题。
推荐阅读
- pytorch - 如何找到二维激活图(pytorch)的均值和协方差
- python - 我可以以返回值作为参数多次运行同一个函数吗?
- excel - 将表格单元格的内容复制到单词中并将其粘贴到excel中时保留格式
- php - PHP在mysql表字符串字段的开头和结尾添加双引号
- javascript - 网络音频/广播流客户端:使用 Howler.js、原生音频、其他库?
- php - 谁可以帮我这个事?
- reactjs - 使用 Google Apps 脚本作为 REST Api
- javascript - Angular:在模板中对异步管道进行分组
- r - 在 [r] 中使用 for 循环代替矩阵索引
- c - 使用 execvp 和 dup2 系统调用后写入终端的问题