flutter to AWS S3 using amplify <asynchronous suspension> error
Although this question was asked in Aug and I hope you already have got your solutions, but still I am going to post the solution for the kids from future.
I was having the same error, after some investigation I found that S3Storage plugin wasn't registered for amplify. Please check your Amplify.addPlugins
, if you didn't forget to register in there.
import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_datastore/amplify_datastore.dart';
import 'package:amplify_flutter/amplify.dart';
import 'package:amplify_storage_s3/amplify_storage_s3.dart';
import 'package:contractor/models/ModelProvider.dart';
import '../../amplifyconfiguration.dart';
import 'dart:developer' as developer;
final AmplifyDataStore _dataStorePlugin = AmplifyDataStore(modelProvider: ModelProvider.instance);
final AmplifyAPI _apiPlugin = AmplifyAPI();
final AmplifyAuthCognito _authPlugin = AmplifyAuthCognito();
final AmplifyStorageS3 _s3Storage = AmplifyStorageS3();
Future<void> configureAmplify() async {
try {
// add Amplify plugins
await Amplify.addPlugins(
[_dataStorePlugin, _apiPlugin, _authPlugin, _s3Storage]);
// configure Amplify
//
// note that Amplify cannot be configured more than once!
await Amplify.configure(amplifyconfig);
} catch (e) {
developer.log("An error occurred while configuring Amplify: $e",
name: 'amplify.error');
}
}
Prasath
தோல்வி நிலையென நினைத்தால் மனிதன் வாழ்வை நினைக்கலாமா > Parunthaguthu Oor Kuruvi, Adangathathu En Piravi, Adanga Pala Madanga > Varum, Thaduththa Adthu Udachchi Varuven, Ippo Vanthu Mothu Da, Kitta > Vanthu Paru Da, Kattaruntha Kala, Nenju Mela Era Pothu Da, Thimiru Da > Thimira Thimira, Nimiru Da Nilama Nilama, Unaru Da Payanam Payanam, > Thodarum Da, Tha Ippo Vanthu Mothu Da, Kitta Vanthu Paru Da Paru Da, Porus ---- My Rule. Don't ask me, What is the Update or What is the Progress, However, I will be give you on correct time
Updated on December 31, 2022Comments
-
Prasath over 1 year
I'm trying to upload Images from Flutter to the AWS S3 bucket using Amplify. I set up the Flutter App using this Documentation, I can't able to upload images to S3,
This is my flutter code
onPressed: () async { for(int i=1;i<images.length;i++) { final key = DateTime.now().toString(); File file = await getImageFileFromAssets(images[i]); try { print('## starting ##'); print('##${file.path} ##'); print('## upload starting ##'); final UploadFileResult result = await Amplify.Storage.uploadFile(local: file, key: key);// .uploadFile(local: file), key: key); print('********Successfully uploaded image: ${result.key}'); } on StorageException catch (e) { print('_________Error uploading image: $e'); } } },
Here is my output
flutter: ## starting ## flutter: ##/Users/prasathsivanathan/Library/Developer/CoreSimulator/Devices/A02325A9-A34C-4390-AF03-C0C2581CB062/data/Containers/Data/Application/34C934EF-84D3-4349-92A3-5754E21321D0/Library/Caches/IMG_0005.JPG ## flutter: ## upload starting ## [VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0 #0 List.[] (dart:core-patch/growable_array.dart:254:60) #1 StorageCategory.uploadFile (package:amplify_flutter/categories/amplify_storage_category.dart:45:19) #2 _MultipleImageDemoState.build.<anonymous closure> (package:gomicropro1/screens/DIY_Imagesection.dart:195:75) <asynchronous suspension>
What went wrong here,