Flutter/Dart SocketException Uploading Video File to URL
Solution 1
Change from a POST to a PUT request resolves the issue.
Solution 2
yes, I have same problem with Dio.
current can't upload data type Uint8List
My temporary solution:
use http lib
http: ^0.12.1
import 'package:http/http.dart' as http;
Future uploadData(Uint8List imageData) async {
await http.put(preData.url, headers: getHeader(), body: imageData);
}
use:
List<int> imageData = File(filePath).readAsBytesSync();
await uploadData(imageData);
hope to help you
Josh Kahane
Updated on December 25, 2022Comments
-
Josh Kahane over 1 year
I am recieving this error message when attempting to upload a video file to the speicified URL:
DioError (DioError [DioErrorType.DEFAULT]: SocketException: OS Error: Connection reset by peer, errno = 54, address = storage.googleapis.com, port = 64995)
Note: It is a
DioError
as I am using thedio
Dart/Flutter package: https://pub.dev/packages/dio I recieve the error using equivilent API such as thehttp
library.Code to upload the video file selected from storage:
//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"); }, );
The URL (
directUpload.url
) is one generated from and provided by the Mux API to their Google Cloud Storage.https://storage.googleapis.com/video-storage-us-east1-uploads/...
When
post
is called, a small amount is uploaded (e.g. 655524 / 17840042) and then the error occurs. The test video is 17.8 Mb in size.Running this on an iOS device or the iOS simulator produces the same result/error.
I have tried:
flutter clean
,flutter upgrade
, deleteingPodfile
andpod repo update
, deleting the app from device. All to no avail.