3

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 the dio Dart/Flutter package: https://pub.dev/packages/dio I recieve the error using equivilent API such as the http 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, deleteing Podfile and pod repo update, deleting the app from device. All to no avail.

Josh Kahane
  • 16,765
  • 45
  • 140
  • 253

5 Answers5

4

Change from a POST to a PUT request resolves the issue.

Josh Kahane
  • 16,765
  • 45
  • 140
  • 253
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

Hưng Trịnh
  • 947
  • 1
  • 12
  • 23
  • Changing to the `http` lib isn't the solution. However, changing from a `POST` to `PUT` request using either lib does. – Josh Kahane Nov 27 '20 at 11:35
2

The error message "Connection reset by peer" appears, if the web services client was waiting for a SOAP response from the remote web services provider and the connection was closed prematurely.

One of the most common causes for this error is a firewall in the middle closing the connection. In this case you could increase the connection timeout in the firewall.You can find the component that closes the connection by capturing and analyzing an IP trace.

Other possible causes are e.g.:

  • resource limitations on the server side like out of memory server

  • process killed

  • overload on the server due to a high amount of traffic

ALSO Try this..

cd ~/flutter
git checkout -b max-in-flight
code packages/flutter_tools/lib/src/devfs.dart # edit kMaxInFlight from 6 to 1
rm bin/cache/flutter_tools*

AND This

flutter clean
flutter channel stable
0

have you tried using http.MultipartRequest method ? As it can be used to transfer large files, you can also try is DIO alternative if present in dio and how to use http.MultipartRequest here is an article https://dev.to/carminezacc/advanced-flutter-networking-part-1-uploading-a-file-to-a-rest-api-from-flutter-using-a-multi-part-form-data-post-request-2ekm

let me know if it works or not.

Akshit Ostwal
  • 451
  • 3
  • 14
0

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.

Answer-

Go your cpanel MultiPHP INI Editor file and increase post_max_size

No need to change u r flutter code, it is right .