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