【问题标题】:flutter to AWS S3 using amplify <asynchronous suspension> error使用放大 <异步挂起> 错误扑向 AWS S3
【发布时间】:2021-08-09 05:58:19
【问题描述】:

我正在尝试使用 Amplify 将图像从 Flutter 上传到 AWS S3 存储桶。我使用这个Documentation 设置了 Flutter App,我无法将图像上传到 S3,

这是我的颤振代码

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

这是我的输出

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>

这里出了什么问题,

【问题讨论】:

    标签: amazon-web-services flutter amazon-s3 aws-amplify


    【解决方案1】:

    虽然这个问题是在 8 月提出的,我希望你已经得到了解决方案,但我仍然会为未来的孩子们发布解决方案。


    我遇到了同样的错误,经过一番调查,我发现 S3Storage 插件未注册用于放大。如果您没有忘记在那里注册,请查看您的Amplify.addPlugins

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

    【讨论】:

      猜你喜欢
      • 2021-01-26
      • 2021-09-18
      • 2021-03-10
      • 1970-01-01
      • 2019-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-21
      相关资源
      最近更新 更多