uploadFilesFromFilePicker method
- @Deprecated('Use uploadFiles instead. This method will be removed in v2.0.0. ' 'Extract file bytes/paths and names from PlatformFile list and pass to uploadFiles.')
Uploads multiple files using PlatformFile.
Deprecated: This method will be removed in a future version.
Use uploadFiles instead. Extract data from PlatformFile list and pass it:
final bytesList = files.map((f) => f.bytes).whereType<Uint8List>().toList();
final paths = files.map((f) => f.path!).toList();
final names = files.map((f) => f.name).toList();
await uploadFiles(
filesBytes: bytesList, // or filePaths: paths
filenames: names,
uploadUrl: uploadUrl,
);
Implementation
@Deprecated(
'Use uploadFiles instead. This method will be removed in v2.0.0. '
'Extract file bytes/paths and names from PlatformFile list and pass to uploadFiles.',
)
Future<List<File>> uploadFilesFromFilePicker(
List<PlatformFile> files, {
String uploadUrl = "/multi-upload-file",
}) async {
try {
if (kIsWeb) {
final bytesList =
files.map((f) => f.bytes).whereType<Uint8List>().toList();
final names = files.map((f) => f.name).toList();
final formData = await _buildMultiFilesFormData(
filesBytes: bytesList,
filenames: names,
);
final response = await dio.post(uploadUrl, data: formData);
return response.bodyAsList<File>();
} else {
final paths = files.map((f) => f.path!).toList();
final names = files.map((f) => f.name).toList();
final formData = await _buildMultiFilesFormData(
filePaths: paths,
filenames: names,
);
final response = await dio.post(uploadUrl, data: formData);
return response.bodyAsList<File>();
}
} catch (e) {
rethrow;
}
}