0

I am using the pdf 3.6.0 library from pub.dev to generate a pdf in flutter web. When I save the document using doc.save(), I get a Future<Uint8List>. I want to upload this file to S3

For android/ios, I first save the Uint8List as a file in a temp directory, using path_provider and then use file.openRead() to get data to upload to S3 and it works perfectly.

I am unable to replicate the same process in flutter web since dart:io is unavailable for flutter web. Even universal_io does not help.

I did try to directly push the uint8list to s3 using the below code

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

But when I open this file again in S3 I get an error saying: "Failed to load PDF document."

How can achieve the same result for the pdf generated for flutter web?

RIP71DE
  • 51
  • 3
  • Please has anyone solved this problem – Codedman Jan 10 '22 at 08:58
  • Long shot: Try converting to string , and then decode it on the backend. Here's a link to encode in flutter [#](https://stackoverflow.com/questions/28565242/convert-uint8list-to-string-with-dart/28570009) – Olamide226 Jan 10 '22 at 16:58

1 Answers1

0

(would add this as comment but don't have enough reputation)

Have you tried wrapping your uint8listData in a Stream.fromIterable(), i.e.

data: Stream.fromIterable(uint8listData),

I happened to notice dio doing this in its test files with a uint8List.

Pat9RB
  • 580
  • 3
  • 7