From 1520485df3e4876e016bc398230f9879bc7de308 Mon Sep 17 00:00:00 2001 From: xuty <xty50337@hotmail.com> Date: Wed, 5 Jan 2022 21:29:20 +0800 Subject: [PATCH] Better upload progress on web --- CHANGELOG.md | 2 ++ lib/src/minio_client.dart | 14 +++++++------- pubspec.yaml | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8968530..284ce85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +# 3.4.0-pre +- Better upload progress on web # 3.3.3 - Fix empty upload error - Update README.md diff --git a/lib/src/minio_client.dart b/lib/src/minio_client.dart index 9361ea1..3fff503 100644 --- a/lib/src/minio_client.dart +++ b/lib/src/minio_client.dart @@ -24,29 +24,29 @@ class MinioRequest extends BaseRequest { return const ByteStream(Stream.empty()); } - if (body is Stream<Uint8List>) { - return ByteStream(body); - } - late Stream<Uint8List> stream; - if (body is String) { + if (body is Stream<Uint8List>) { + stream = body; + } else if (body is String) { final data = Utf8Encoder().convert(body); headers['content-length'] = data.length.toString(); stream = Stream<Uint8List>.value(data); } else if (body is Uint8List) { stream = Stream<Uint8List>.value(body); headers['content-length'] = body.length.toString(); + } else { + throw UnsupportedError('Unsupported body type: ${body.runtimeType}'); } - stream = stream.transform(MaxChunkSize(1 << 16)); - if (onProgress == null) { return ByteStream(stream); } var bytesRead = 0; + stream = stream.transform(MaxChunkSize(1 << 16)); + return ByteStream( stream.transform( StreamTransformer.fromHandlers( diff --git a/pubspec.yaml b/pubspec.yaml index f4c483e..377fecc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: minio description: Unofficial MinIO Dart Client SDK that provides simple APIs to access any Amazon S3 compatible object storage server. -version: 3.3.3 +version: 3.4.0-pre homepage: https://github.com/xtyxtyx/minio-dart issue_tracker: https://github.com/xtyxtyx/minio-dart/issues -- GitLab