uploadFileFromImagePicker method
Uploads a file from an XFile
object to the specified upload URL.
Parameters:
file
: TheXFile
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> uploadFileFromImagePicker(
XFile file, {
String uploadUrl = '/upload-file',
}) async {
FormData formData = FormData();
if (kIsWeb) {
final bytes = await file.readAsBytes();
formData.files.add(MapEntry('file', MultipartFile.fromBytes(bytes)));
} else {
formData.files
.add(MapEntry('file', await MultipartFile.fromFile(file.path)));
}
return dio
.post(uploadUrl, data: formData)
.then((response) => response.body<File>());
}