在Flutter iOS应用中,我试图使用预签名URL将文件上传到AWS S3。
适用于小文件。但是,在上传5x MB文件时会引发以下错误。 可以在iOS Simulator中成功上传文件,但在真实设备中失败,则很奇怪。
以下是错误消息。
flutter: Exception: SocketException: Read failed (OS Error: Connection reset by peer, errno = 54), address = s3.eu-central-1.amazonaws.com, port = 54505
flutter: Stacktrace: #0 _NativeSocket.read (dart:io-patch/socket_patch.dart:718:38)
#1 _RawSocket.read (dart:io-patch/socket_patch.dart:1457:22)
#2 _RawSecureSocket._readSocketOrBufferedData (dart:io/secure_socket.dart:974:22)
#3 _ExternalBuffer.writeFromSource (dart:io/secure_socket.dart:1216:30)
#4 _RawSecureSocket._readSocket (dart:io/secure_socket.dart:983:16)
#5 _RawSecureSocket._readHandler (dart:io/secure_socket.dart:776:5)
#6 _RawSecureSocket._eventDispatcher (dart:io/secure_socket.dart:764:9)
#7 _rootRunUnary (dart:async/zone.dart:1138:13)
#8 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#9 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
#10 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
#11 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:265:7)
#12 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:766:19)
#13 _StreamController._add (dart:async/stream_controller.dart:642:7)
#14 _StreamController.add (dart:async/stream_controller.dart:588:5)
#15 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1399:33)
#16 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:919:14)
#17 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#18 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
我的代码如下。
import 'package:http/http.dart' as http;
Response response = await http.put(
url,
headers: {
"Connection": "Keep-Alive",
},
body: await file.readAsBytes(),
).timeout(Duration(minutes: 5), onTimeout: () {
developer.log("TIMEOUT");
return null;
});
谁能帮助我做错什么?
更新1: 扑医生-v如下
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76, locale en-GB)
• Flutter version 1.12.13+hotfix.9 at /Users/leochiu/Documents/Sources/flutter
• Framework revision f139b11009 (6 weeks ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/leochiu/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 44.0.2
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[!] VS Code (version 1.45.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (1 available)
• S Box8Q40C • 0123456789 • android-arm • Android 4.4.2 (API 19)
! Doctor found issues in 1 category.
答案 0 :(得分:0)
对我来说,解决方案是添加下一个标题
accept-encoding: gzip, deflate, br