【发布时间】:2021-03-03 19:34:09
【问题描述】:
我在尝试将视频文件上传到指定的 URL 时收到此错误消息:
DioError (DioError [DioErrorType.DEFAULT]: SocketException: OS Error: Connection reset by peer, errno = 54, address = storage.googleapis.com, port = 64995)
注意:这是一个 DioError,因为我正在使用 dio Dart/Flutter 包:https://pub.dev/packages/dio 我使用等效 API(例如 http 库)收到错误。
上传从存储中选择的视频文件的代码:
//File videoFile...
FormData data = FormData.fromMap({
"videoFile": await MultipartFile.fromFile(videoFile.path),
});
Response response = await Dio().post(
directUpload.url,
data: data,
onSendProgress: (int sent, int total) {
print("$sent $total");
},
);
网址 (directUpload.url) 是由 Mux API 生成并提供给他们的 Google Cloud Storage 的。
https://storage.googleapis.com/video-storage-us-east1-uploads/...
调用post时,上传少量(如655524 / 17840042),然后报错。测试视频大小为 17.8 Mb。
在 iOS 设备或 iOS 模拟器上运行它会产生相同的结果/错误。
我试过:flutter clean、flutter upgrade、删除Podfile和pod repo update,从设备中删除应用程序。一切都无济于事。
【问题讨论】:
-
查看 URL 所需的标头,您提供的标头可能缺少 keep-alive 标头!
-
@Yadu 添加
connection: keep-alive标头没有变化。 -
Keep-Alive,看看帽子!
-
仍然得到错误。我的理解是标题无论如何都不区分大小写。
-
今天是我了解到:),我宁愿使用默认流和 HttpClient 而不是 http 和 dio,因为错误表明它可能是服务器内部错误,操作系统错误!
标签: ios flutter dart upload mux