uploadFiles method

Future<List<File>> uploadFiles({
  1. required List<String> filePaths,
  2. String uploadUrl = '/multi-upload-file',
})

Uploads multiple files to the specified upload URL.

Parameters:

  • filePaths: A list of file paths 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>> uploadFiles({
  required List<String> filePaths,
  String uploadUrl = '/multi-upload-file',
}) async {
  FormData formData = FormData();
  for (var filePath in filePaths) {
    formData.files.add(
      MapEntry(
        'files',
        await MultipartFile.fromFile(
          filePath,
          filename: path.basename(filePath),
        ),
      ),
    );
  }
  return dio
      .post(
        uploadUrl,
        data: formData,
      )
      .then((response) => response.bodyAsList<File>());
}