Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Download files

Amplify Flutter v0 is now in Maintenance Mode until July 19th, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v0.

Please use the latest version (v1) of Amplify Flutter to get started.

If you are currently using v0, follow these instructions to upgrade to v1.

There are two ways of getting data that was previously uploaded:

Download File

You can download file to a local directory using Amplify.Storage.downloadFile.

You can use the path_provider package to create a local file in the user's documents directory where you can store the downloaded data.

1import 'dart:io';
2import 'package:path_provider/path_provider.dart';
3
4Future<void> downloadFile() async {
5 final documentsDir = await getApplicationDocumentsDirectory();
6 final filepath = documentsDir.path + '/example.txt';
7 final file = File(filepath);
8
9 try {
10 final result = await Amplify.Storage.downloadFile(
11 key: 'ExampleKey',
12 local: file,
13 onProgress: (progress) {
14 safePrint('Fraction completed: ${progress.getFractionCompleted()}');
15 },
16 );
17 final contents = result.file.readAsStringSync();
18 // Or you can reference the file that is created above
19 // final contents = file.readAsStringSync();
20 safePrint('Downloaded contents: $contents');
21 } on StorageException catch (e) {
22 safePrint('Error downloading file: $e');
23 }
24}

Generate a download URL

You can get a downloadable URL for the file in storage by its key using Amplify.Storage.getUrl.

1Future<void> getDownloadUrl() async {
2 try {
3 final result = await Amplify.Storage.getUrl(key: 'ExampleKey');
4 // NOTE: This code is only for demonstration
5 // Your debug console may truncate the printed url string
6 safePrint('Got URL: ${result.url}');
7 } on StorageException catch (e) {
8 safePrint('Error getting download URL: $e');
9 }
10}