uploadFilesFromFilePicker method
Uploads multiple files from a list of PlatformFile
objects to the specified upload URL.
Parameters:
files
: A list ofPlatformFile
objects representing the files to be uploaded.uploadUrl
: The URL to which the files will be uploaded. Defaults to/multi-upload-file
.
Returns:
Implementation
Future<List<File>> uploadFilesFromFilePicker(
List<PlatformFile> files, {
String uploadUrl = '/multi-upload-file',
}) async {
if (kIsWeb) {
final List<File> uploadedFiles = [];
for (var f in files) {
uploadedFiles.add(await uploadFileFromFilePicker(f));
}
return uploadedFiles;
}
FormData formData = FormData();
for (var file in files) {
formData.files
.add(MapEntry('files', await MultipartFile.fromFile(file.path!)));
}
return dio
.post(uploadUrl, data: formData)
.then((response) => response.bodyAsList<File>());
}