uploadFile method

Future<File> uploadFile({
  1. required String filePath,
  2. String uploadUrl = '/upload-file',
})

Implementation

Future<File> uploadFile({
  required String filePath,
  String uploadUrl = '/upload-file',
}) async {
  String filename = path.basename(filePath);
  FormData formData = FormData.fromMap(
    {
      'file': await MultipartFile.fromFile(filePath, filename: filename),
    },
  );

  return dio
      .post(
        uploadUrl,
        data: formData,
      )
      .then(
        (response) => response.body<File>(),
      );
}