dart-lang / http

A composable API for making HTTP requests in Dart.
https://pub.dev/packages/http
BSD 3-Clause "New" or "Revised" License
1.02k stars 354 forks source link

MultipartRequest is not working correctly on Flutter WEB #917

Open ProfEPT-ricardo-sj opened 1 year ago

ProfEPT-ricardo-sj commented 1 year ago
Stream<List<int>> pseudoFileGenerator(int size) async* {
  List<int> list = [];
  for (int i = 0; i < size; i++) {
    list.add(i);
    if (i % 1024 == 0) {
      print('1kb');
      yield List.from(list);
      list = [];
    }
  }
  if (list.isEmpty == false) {
    yield List.from(list);
  }
}

//--------------------------------------------------------------------------------
sendMultpart(url) async{

      http.MultipartRequest multipartRequest = http.MultipartRequest('POST', url);

      http.MultipartFile multipartFile = http.MultipartFile(
        'campoField',
        pseudoFileGenerator(size),
        size,
        filename: '',
        contentType: mimeType,
      );

      multipartRequest.files.add(
        multipartFile,
      );

      await multipartRequest.send();

}

Expected results

when i call sendMultpart(...) on flutter for windows all code is done right: A chunk of bytes is load in memory and than sent to server, than another chunk of bytes is read and sent to server until done!

The problem is on WEB version of flutter. when I run this code on flutter web all the bytes is first load on memory and only after that the information is sent to server.

With this behavior my web code version need first load all file on memory to after that send to server. This is a very wrong behavior.

I expected that the web version work in same way of the windows version.

Actual results

The result of this is that I lose the chance to put my project on flutter in the company I work. Now we have to migrate to another tecnology.

Coinners commented 8 months ago

any updates on this?