MultipartFile.fromString constructor Null safety

  1. String value,
  2. {String? filename,
  3. MediaType? contentType}

Creates a new MultipartFile from a string.

The encoding to use when translating value into bytes is taken from contentType if it has a charset set. Otherwise, it defaults to UTF-8. contentType currently defaults to text/plain; charset=utf-8, but in the future may be inferred from filename.


factory MultipartFile.fromString(
  String value, {
  String? filename,
  MediaType? contentType,
}) {
  contentType ??= MediaType('text', 'plain');
  var encoding = encodingForCharset(contentType.parameters['charset'], utf8);
  contentType = contentType.change(parameters: {'charset':});

  return MultipartFile.fromBytes(
    filename: filename,
    contentType: contentType,