'Error when downloading file from Flutter Amplify Storage

I get the error below when downloading an audio file from Amplify Storage on an iOS device, both Simulator and a device. It all works perfectly fine when doing it on an Android emulator and device.

When downloading a JSON-file from the Storage it's working on both platforms without errors.

The JSON I'm downloading in the app as a guest, while the audio file is downloaded as private, but I don't see why this should make a difference when it's working on 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)

Here is the code I use to download the file:

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';
    }
  }
}

Update: I have now created an issue on the Amplify flutter Github

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



Solution 1:[1]

The problem was caused by the /audio/ folder not existing on iOS. This answer tells how you can create the path, if it doesn't exist.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JoakimMellonn