http icon indicating copy to clipboard operation
http copied to clipboard

[flutter-web] MultipartRequest does not work

Open fralways opened this issue 3 years ago • 0 comments

When we use following code, the upload progress goes fast to 1.0 and then hangs there until upload is completed.

This is preventing us from showing upload progress bar to the users.

This is happening in flutter-web, flutter 2.5.3 and 2.8.1.

final request = MultipartRequest('PUT', Uri.parse('some-storage-uri'));
    request.files.add(MultipartFile.fromBytes('file', data, filename: filename));

      final responseStream = request.finalize();

      final totalLength = request.contentLength;
      var uploadedLength = 0.0;
      responseStream.listen((value) {
        uploadedLength += value.length;
        final progress = 1.0 * uploadedLength / totalLength;
        // print('sent: $uploadedLength');
        // print('total: $totalLength');
        print('upload progress: $progress');
      }, onDone: () {
        //   print('upload success');
      }, onError: (e) {
        print(e);
      });

Output:

upload progress: 0.000006970631411096944
updated progress to: 0.000006970631411096944
upload progress: 0.00001742657852774236
updated progress to: 0.00001742657852774236
upload progress: 0.9999926525777019
updated progress to: 0.9999926525777019
upload progress: 0.9999928409731453
updated progress to: 0.9999928409731453
upload progress: 1
updated progress to: 1

fralways avatar Jan 06 '22 18:01 fralways