uploadFileFromFilePicker method
Uploads a file from a PlatformFile
object to the specified upload URL.
Parameters:
file
: ThePlatformFile
object representing the file to be uploaded.uploadUrl
: The URL to which the file will be uploaded. Defaults to/upload-file
.
Returns:
Implementation
Future<File> uploadFileFromFilePicker(
PlatformFile file, {
String uploadUrl = '/upload-file',
}) async {
FormData formData = FormData();
if (kIsWeb && file.bytes != null) {
formData.files
.add(MapEntry('file', MultipartFile.fromBytes(file.bytes!)));
} else {
formData.files.add(
MapEntry(
'file',
await MultipartFile.fromFile(file.path!),
),
);
}
return dio
.post(uploadUrl, data: formData)
.then((response) => response.body<File>());
}