forked from djade007/cloudinary_public
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4d91fe
commit 03e791f
Showing
6 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:http/http.dart' as http; | ||
|
||
class MultipartRequest extends http.MultipartRequest { | ||
/// Creates a new [MultipartRequest]. | ||
MultipartRequest( | ||
String method, | ||
Uri url, { | ||
this.onProgress, | ||
}) : super(method, url); | ||
|
||
final void Function(int bytes, int totalBytes)? onProgress; | ||
|
||
/// Freezes all mutable fields and returns a | ||
/// single-subscription [http.ByteStream] | ||
/// that will emit the request body. | ||
@override | ||
http.ByteStream finalize() { | ||
final byteStream = super.finalize(); | ||
if (onProgress == null) return byteStream; | ||
|
||
final total = contentLength; | ||
var bytes = 0; | ||
|
||
final t = StreamTransformer.fromHandlers( | ||
handleData: (List<int> data, EventSink<List<int>> sink) { | ||
bytes += data.length; | ||
onProgress?.call(bytes, total); | ||
sink.add(data); | ||
}, | ||
); | ||
final stream = byteStream.transform(t); | ||
return http.ByteStream(stream); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
typedef ProgressCallback = void Function(int count, int total); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters