SocketException: OS Error: Broken pipe on flutter

Viewed 752

i've been having trouble with video upload. I'm using Express JS/Node JS as a backend. The thing is, the upload works when i upload a video of 2 seconds and it works 100% with postman. but when i try to upload a big video from the app i get :

SocketException: OS Error: Broken pipe, errno = 32, address = 51.254.241.1, port = 47908

and this is my code :

var stream = new http.ByteStream(file.openRead())..cast();
      var request = http.MultipartRequest(
          "POST",
          Uri.parse(sp.getString(SharedPreferencesManager
                  .LAST_SELECTED_ESTABLISHMENT_ENDPOINT) +
              "api/group/uploadVideoFile"));
      request.fields["email"] = sp.getString(SharedPreferencesManager.EMAIL);
      request.fields["groupId"] = group.id;
      request.files.add(http.MultipartFile("video", stream, await file.length(),
          filename: file.absolute.path));
      // request.files
      //     .add(http.MultipartFile.fromBytes("video", file.readAsBytesSync()));
      // request.files
      //     .add(await http.MultipartFile.fromPath("video", file.absolute.path));
      request.headers.addAll({
        "Connection": "keep-alive",
        "Accept-Encoding": "gzip,deflate,br",
        "Accept": "application/json",
        "Authorization": "Bearer " + sp.getString("TOKEN"),
        "X-Auth-Token": FlutterConfig.get('X_AUTH_TOKEN')
      });
      request.send().then((value) => print("jawk behy $value"),
          onError: (error) => print("error : $error"));
      var response = await request.send();
      return  json.decode(await response.stream.bytesToString());
0 Answers
Related