从 Flutter Amplify Storage 下载文件时出错

Error when downloading file from Flutter Amplify Storage

在 iOS 设备(模拟器和设备)上从 Amplify Storage 下载音频文件时出现以下错误。在 Android 模拟器和设备上运行时一切正常。

从存储中下载 JSON 文件时,它可以在两个平台上正常运行。

JSON 我正在以访客身份在应用程序中下载,而音频文件是作为私有文件下载的,但我不明白为什么这在 Android.

StorageException(message: Unexpected error occurred with message: Domain: [NSCocoaErrorDomain
Code: [4
LocalizedDescription: [The file doesn’t exist.
LocalizedFailureReason: [The file doesn’t exist.
LocalizedRecoverySuggestion: [, recoverySuggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't.
Issue encountered at: file: /Users/x/Documents/Github/TransscriberAI-App/Flutter/transscriber/ios/Pods/Amplify/Amplify/Categories/Storage/Error/StorageError.swift
function: recoverySuggestion line: 63, underlyingException: null)

这是我用来下载文件的代码:

Future<String> getAudioPath(String key) async {
  final docDir = await getTemporaryDirectory();
  final filePath = docDir.path + '/audio/$key';
  File file = File(filePath);
  final S3DownloadFileOptions options = S3DownloadFileOptions(
    accessLevel: StorageAccessLevel.private,
  );

  if (await file.exists()) {
    return filePath;
  } else {
    try {
      await Amplify.Storage.downloadFile(
        key: key,
        local: file,
        options: options,
      );
      return filePath;
    } on StorageException catch (e) {
      print('Error downloading file: $e');
      return 'null';
    }
  }
}

更新: 我现在已经在 Amplify flutter 上创建了一个问题 Github

https://github.com/aws-amplify/amplify-flutter/issues/1276

问题是由 iOS 上不存在的 /audio/ 文件夹引起的。 告诉你如何创建路径,如果它不存在。