```dart import 'dart:io'; import 'package:path_provider/path_provider.dart'; Future downloadProtected(String cognitoIdentityId) async { // Create a file to store downloaded contents final documentsDir = await getApplicationDocumentsDirectory(); final filepath = documentsDir.path + '/example.txt'; final file = File(filepath); // Set access level and Cognito Identity ID. // Note: `targetIdentityId` is only needed when downloading // protected files of a user other than the one currently // logged in. final downloadOptions = S3DownloadFileOptions( accessLevel: StorageAccessLevel.protected, // e.g. us-west-2:2f41a152-14d1-45ff-9715-53e20751c7ee targetIdentityId: cognitoIdentityId, ); // Download protected file and read contents try { await Amplify.Storage.downloadFile( key: 'ExampleKey', local: file, options: downloadOptions, ); final contents = file.readAsStringSync(); safePrint('Got protected file with contents: $contents'); } on StorageException catch (e) { safePrint('Error downloading protected file: $e'); } } ```