image method

Future<MultipartFile> image({
  1. String key = "image",
})

return an async MultipartFile for uploading using key, example:

  • {"key" : "image_path.png"}

Implementation

Future<MultipartFile> image({String key = "image"}) async => _file == null
? throw Exception('No image loaded')
: kIsWeb
  ? MultipartFile.fromBytes(
    key,
    _file!.bytes!,
    filename    : '$key.$_extension',
    contentType : MediaType("image", _extension)
  )
  : await MultipartFile.fromPath(
    key,
    _file!.path!,
    filename    : '$key.$_extension',
    contentType : MediaType("image", _extension)
  );