uploadFilesFromImagePicker method

Future<List<File>> uploadFilesFromImagePicker(
  1. List<XFile> files, {
  2. String uploadUrl = '/multi-upload-file',
})

Uploads multiple files from a list of XFile objects to the specified upload URL.

Parameters:

  • files: A list of XFile objects representing the files to be uploaded.
  • uploadUrl: The URL to which the files will be uploaded. Defaults to /multi-upload-file.

Returns:

  • A Future that resolves to a list of File objects representing the uploaded files.

Implementation

Future<List<File>> uploadFilesFromImagePicker(
  List<XFile> files, {
  String uploadUrl = '/multi-upload-file',
}) async {
  if (kIsWeb) {
    final List<File> uploadedFiles = [];
    for (var f in files) {
      uploadedFiles.add(await uploadFileFromImagePicker(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>());
}