socket.io-client-dart icon indicating copy to clipboard operation
socket.io-client-dart copied to clipboard

reconnect when upload big data to socket.io server

Open fengmao opened this issue 3 years ago • 1 comments

ElevatedButton(
    child: const Text('upload image'),
    onPressed: () async {
      final XFile? image =
          await _picker.pickImage(source: ImageSource.gallery);
      setState(() {
        _imagePath = image?.path;
        _imageFile = image;
      });
    },
  ),
  ElevatedButton(
    child: const Text('take a photo'),
    onPressed: () async {
      final XFile? image =
          await _picker.pickImage(source: ImageSource.camera);
      setState(() {
        _imagePath = image?.path;
        _imageFile = image;
      });
    },
  ),
  ElevatedButton(
    child: const Text('upload'),
    onPressed: () async {
      var bytes = await _imageFile?.readAsBytes();
      String base64Image = base64Encode(bytes!);
      print(base64Image);
      Map res = await FutureUtil.emitWithAck(
              CommonUtil.socket,
              'avatarRequest',
              { 'bytes': base64Image });
          print(res);
      // var res = await FutureUtil.emitWithAck(CommonUtil.socket,
      //     'avatarRequest', {'content': base64Encode(bytes!.toList())});
      // print(res);
      // setState(() {
      //   path = res['url'];
      // });
    },
  ),

I use image_picker to choose image, the device i use is Android, when i try to send base64 image data to socket.io server, the app print "connect success", it means the connection reconnected when upload big data, please help me

fengmao avatar Mar 03 '22 02:03 fengmao

You can consider to send bytes data directly without converting to String as Base64, and if the bytes is too big to send once, you can split it into multiple-packets, and then send them one by one, and collect them at the server side to merge them to a file.

jumperchen avatar Apr 18 '22 02:04 jumperchen