【问题标题】:How to properly call the S3 file inside flutter streams?如何在颤振流中正确调用 S3 文件?
【发布时间】:2021-10-03 23:44:36
【问题描述】:

我对如何在流中调用s3 objects 有点困惑。

Get 请求在 AWS 中计费,因此在流中包含图像会导致对 S3 对象的请求过多。

对于具有图像和文本内容(例如事件)的颤振小部件是否遵循任何方法

【问题讨论】:

    标签: flutter amazon-s3 graphql amplify


    【解决方案1】:

    使用 Stream 并不一定意味着您会经常执行 API 调用。您仍然可以使用 Future 进行 API 调用并将其响应添加到 StreamController。

    这是一个例子。

    // Let Repository contain API requests
    final _repository = Repository();
    final _albumFetcher = StreamController<List<AlbumModel>>();
    
    Stream<List<AlbumModel>> get allAlbums => _albumFetcher.stream;
    
    fetchAlbum() async {
      // Fetch data and add the response on your StreamController
      List<AlbumModel> listAlbums = await _repository.fetchAllAlbums();
      _albumFetcher.sink.add(listAlbums);
    }
    

    只有在调用 fechAlbum() 时才会更新 Stream。 Stream 不会持续发送 API 请求来获取数据。

    这是我创建的sample,您可以尝试一下。

    【讨论】:

      【解决方案2】:

      有几种方法可以做到这一点。一种方法是使用Signature V4sign your request 并将您的文件POST 到S3。

      【讨论】:

        猜你喜欢
        • 2023-03-15
        • 2021-10-06
        • 2023-04-06
        • 1970-01-01
        • 1970-01-01
        • 2020-04-16
        • 2023-04-02
        • 2021-10-30
        • 2021-07-04
        相关资源
        最近更新 更多