GithubHelp home page GithubHelp logo

Comments (6)

fromlabs avatar fromlabs commented on July 19, 2024 1

Yes I've already tried your solution and it works.

Meanwhile I found a workaround on my code:

dio.MultipartFile.fromBytes(
  Uint8List.fromList(fileData),
  filename: fileName,
  contentType: contentType,
),

Thanks @AlexV525!

from dio.

AlexV525 avatar AlexV525 commented on July 19, 2024 1

Huge thanks for your inputs!

from dio.

fromlabs avatar fromlabs commented on July 19, 2024

I think is related to:

I suppose the problem is in form_data.dart:

final controller = StreamController<Uint8List>(sync: false);

...

Future<void>(() async {
  for (final file in files) {
    writeUtf8('--$boundary$_rn');
    writeUtf8(_headerForFile(file));
    await writeStreamToSink(file.value.finalize(), controller);
    writeLine();
  }
}).then((_) {
  writeUtf8('--$boundary--$_rn');
}).whenComplete(() {
  controller.close();
});

multipart_file.dart
Stream<List<int>> finalize();

Calling writeStreamToSink(Stream<List<int>>, StreamController<Uint8List>) throws a TypeError because is trying to add List<int> to a Uint8List sink.

from dio.

AlexV525 avatar AlexV525 commented on July 19, 2024

@fromlabs Could you try updating the implementation to below solve the problem?

Future<void>(() async {
  for (final file in files) {
    writeUtf8('--$boundary$_rn');
    writeUtf8(_headerForFile(file));
    await writeStreamToSink<Uint8List>(
      file.value
          .finalize()
          .map((e) => e is Uint8List ? e : Uint8List.fromList(e)),
      controller,
    );
    writeLine();
  }
}).then((_) {
  writeUtf8('--$boundary--$_rn');
}).whenComplete(() {
  controller.close();
});

from dio.

AlexV525 avatar AlexV525 commented on July 19, 2024

@fromlabs Are you able to extract a minimal reproducible example? I'm wondering why the issue (if it exists) escapes from our tests.

from dio.

fromlabs avatar fromlabs commented on July 19, 2024

I think because formdata_test.dart doesn't test directly MultipartFile.fromBytes with real List<int>, but tests just MultipartFile.fromString, MultipartFile.fromFile and MultipartFile.fromFileSync which work under the hood with Uint8List.

from dio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.