MultipartFile.fromStream constructor

MultipartFile.fromStream(
  1. Stream<List<int>> data(),
  2. int length, {
  3. String? filename,
  4. DioMediaType? contentType,
  5. Map<String, List<String>>? headers,
})

Creates a new MultipartFile from a chunked Stream of bytes. The length of the file in bytes must be known in advance. If it's not, read the data from the stream and use MultipartFile.fromBytes instead.

contentType currently defaults to application/octet-stream, but in the future may be inferred from filename.

Implementation

MultipartFile.fromStream(
  Stream<List<int>> Function() data,
  this.length, {
  this.filename,
  DioMediaType? contentType,
  Map<String, List<String>>? headers,
})  : _dataBuilder = data,
      headers = caseInsensitiveKeyMap(headers),
      contentType = contentType ?? MediaType('application', 'octet-stream');