uploadFileFromImagePicker method
- @Deprecated('Use uploadFile instead. This method will be removed in v2.0.0. ' 'Extract file.path/bytes and file.name from XFile and pass to uploadFile.')
- XFile file, {
- String uploadUrl = "/upload-file",
Uploads a file using XFile.
Deprecated: This method will be removed in a future version.
Use uploadFile instead. Extract data from XFile and pass it:
await uploadFile(
filePath: file.path, // or bytes: await file.readAsBytes()
filename: file.name,
uploadUrl: uploadUrl,
);
Implementation
@Deprecated(
'Use uploadFile instead. This method will be removed in v2.0.0. '
'Extract file.path/bytes and file.name from XFile and pass to uploadFile.',
)
Future<File> uploadFileFromImagePicker(
XFile file, {
String uploadUrl = "/upload-file",
}) async {
try {
final formData = await _buildSingleFileFormData(
bytes: kIsWeb ? await file.readAsBytes() : null,
filePath: kIsWeb ? null : file.path,
filename: file.name,
);
final response = await dio.post(uploadUrl, data: formData);
return response.body<File>();
} catch (e) {
rethrow;
}
}