0

I am trying to upload a video to s3 using preassigned URL using streams but unable to get percentage uploaded.

final streamedRequest = new StreamedRequest(
                 'PUT', Uri.parse(presignedUrl))
               ..headers
                   .addAll({HttpHeaders.contentTypeHeader: 'video/quicktime'});
             streamedRequest.contentLength = await file.length();
             file.openRead().listen((chunk) {
               setState(() {
                   this.chunkUploaded += chunk.length;
                   this.percentageUploaded =
                     (chunkUploaded / streamedRequest.contentLength) * 100;
               });
               streamedRequest.sink.add(chunk);
             }, onDone: () {
               streamedRequest.sink.close();
             });
             var videoUploadResponse = await streamedRequest.send();```
kunaljosh369
  • 195
  • 1
  • 3
  • 12
  • If you print('$percentageUploaded'), it prints the correct percentage? – Pablo Barrera Oct 29 '19 at 09:36
  • It gives me 100% even after video is not fully uploaded. After 100% it takes more time and than i get Response status 200. – kunaljosh369 Oct 29 '19 at 09:40
  • it goes from 0 -100 thaen i have to wait for some time to get success response – kunaljosh369 Oct 29 '19 at 09:40
  • No it is not printing correct percentage uploaded. – kunaljosh369 Oct 29 '19 at 10:05
  • I found that this is a real pain to deal with in dart. I'd advise you to take a look at the `dio` plugin – Julien Lachal Oct 29 '19 at 11:23
  • Does this answer your question? [Flutter: How to get upload / download progress for http requests](https://stackoverflow.com/questions/50455131/flutter-how-to-get-upload-download-progress-for-http-requests) – Richard Heap Oct 29 '19 at 13:07
  • You will probably find that the device has sent all the bytes (and reached 100%) but the server hasn't processed them all yet (maybe it's saving to disk, etc). Only when it has successfully done that will it send 200. Of course, you can't predict how long that processing will take, so you cannot indicate progress during that time. (1) uploading bytes... (2) server processing time... (3) server sends 200. Your indicator will have to show 100% after step 1, even though step 2 may take a while. You can test this using a plain Dart file run on your laptop. – Richard Heap Oct 29 '19 at 13:14

0 Answers0