【问题标题】:Uploading pdf generated in flutter web to S3将flutter web中生成的pdf上传到S3
【发布时间】:2021-11-11 19:18:22
【问题描述】:

我正在使用来自 pub.dev 的 pdf 3.6.0 库在 Flutter Web 中生成 pdf。当我使用doc.save() 保存文档时,我得到一个Future<Uint8List>。我想将此文件上传到 S3

对于 android/ios,我首先将Uint8List 保存为临时目录中的文件,使用path_provider,然后使用file.openRead() 获取数据以上传到 S3,它可以完美运行。

我无法在 Flutter Web 中复制相同的过程,因为 dart:io 不适用于 Flutter Web。即使universal_io 也无济于事。

我确实尝试使用以下代码将uint8list 直接推送到 s3

await dio.put(
      s3PresignedURLForPUT,
      data: uint8listData,
      options: Options(
        contentType: "application/pdf",
        headers: {
          "Content-Length": length,
        },
      ),
      onSendProgress: (int sentBytes, int totalBytes) {
        double progressPercent = sentBytes / totalBytes * 100;
        print("$progressPercent %");
      },
    );

但是当我在 S3 中再次打开此文件时,我收到一条错误消息:“无法加载 PDF 文档。”

flutter web生成的pdf如何达到同样的效果?

【问题讨论】:

  • 请问有人解决了这个问题
  • 长镜头:尝试转换为 string ,然后在后端对其进行解码。这是在颤振中编码的链接#

标签: flutter dart amazon-s3 flutter-web dart-io


【解决方案1】:

(将其添加为评论,但没有足够的声誉)

您是否尝试过将 uint8listData 包装在 Stream.fromIterable() 中,即

data: Stream.fromIterable(uint8listData),

我碰巧注意到 dio 在其测试文件中使用 uint8List 执行此操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 2018-08-27
    相关资源
    最近更新 更多