uploadFile method
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:
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>(),
);
}