uploadFile method

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

Uploads a file to the specified upload URL.

Parameters:

  • filePath: The path to the file to be uploaded.
  • uploadUrl: The URL to which the file will be uploaded. Defaults to /upload-file.

Returns:

  • A Future that resolves to a File object representing the uploaded 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>(),
      );
}