getMultipartFile static method

Future<MultipartFile> getMultipartFile({
  1. required VPlatformFile source,
  2. String fieldName = "file",
})

Implementation

static Future<http.MultipartFile> getMultipartFile({
  required VPlatformFile source,
  String fieldName = "file",
}) async {
  final mimeType = source.mimeType;
  final fileLocalPath = source.fileLocalPath;
  final bytes = source.bytes;

  final contentType = mimeType != null ? MediaType.parse(mimeType) : null;
  final file = bytes != null
      ? http.MultipartFile.fromBytes(
          fieldName,
          bytes,
          filename: source.name,
          contentType: contentType,
        )
      : await http.MultipartFile.fromPath(
          fieldName,
          fileLocalPath!,
          filename: source.name,
          contentType: contentType,
        );

  return file;
}