saveMultipleFiles method

  1. @override
Future<List<String>> saveMultipleFiles({
  1. required List<Uint8List> dataList,
  2. required List<String> fileNameList,
  3. required List<String> mimeTypeList,
})
override

Saves multiple files using platform-specific implementation.

Returns a list of saved file paths (or identifiers) for each file. On iOS the paths are temporary staging locations; on Web they indicate that a browser download was triggered.

dataList: List of file data in bytes. fileNameList: List of file names with extensions. mimeTypeList: List of corresponding MIME types.

Implementation

@override
Future<List<String>> saveMultipleFiles({
  required List<Uint8List> dataList,
  required List<String> fileNameList,
  required List<String> mimeTypeList,
}) async {
  final results = <String>[];

  for (int i = 0; i < dataList.length; i++) {
    final blob = web.Blob(
      [dataList[i].toJS as JSAny].toJS,
      web.BlobPropertyBag(type: mimeTypeList[i]),
    );
    final url = web.URL.createObjectURL(blob);
    final anchor =
        web.document.createElement('a') as web.HTMLAnchorElement
          ..href = url
          ..download = fileNameList[i];

    web.document.body?.append(anchor);
    anchor.click();
    anchor.remove();
    web.URL.revokeObjectURL(url);

    results.add('download_triggered:${fileNameList[i]}');

    // Small delay between multiple downloads to avoid browser throttling.
    if (i < dataList.length - 1) {
      await Future<void>.delayed(const Duration(milliseconds: 100));
    }
  }

  return results;
}