-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress event(s) for FormData requests #103
Comments
Want the same, found any workaround @jagged3dge ??? |
I'm afraid I haven't. I couldn't pursue it further due to limited time constraints. I'm hoping package authoring team might have some pointers |
I have no idea about it yet, because neither |
I made sample app which shows how to implement upload/download with progress bar, so maybe you find it useful to make dio.fileupload. |
@salk52 I have seen your code, but I am sorry to say that your code may be not correct. In your code, the The follow code snippet from your code, and I comment the new StreamTransformer.fromHandlers(
handleData: (data, sink) {
byteCount += data.length;
if (onUploadProgress != null) {
onUploadProgress(byteCount, totalByteLength);
}
// comment this line, the file will not be uploaded, but the progress still go
//sink.add(data);
},
handleError: (error, stack, sink) {
throw error;
},
handleDone: (sink) {
sink.close();
// UPLOAD DONE;
},
), If not call |
Yes, you are partially right, but it's not just reading file and I'll try to explain. First of all sink.add(data); should be call first, then onUploadProgress(byteCount, totalByteLength); Calling sink.add(data); is crucial for this example. Stream reads bytes in chunks and add them into network stream by sink.add(data) which is synchronous call. So if sink.add(data) cant add bytes to underlaying network stream it will throw an exception. So if you start uplading 100 MB file, and you turn off wifi on emulator/phone, the progress will stop. So you indirectly know that bytes are sent or not. |
I've created a PR #141 that attempts to address this. I'm converting the FormData.bytes to a stream, then uploading that stream and providing an OnUploadProgress. |
fixed! response = await dio.post(
"http://www.dtworkroom.com/doris/1/2.0.0/test",
data: {"aa": "bb" * 22},
onUploadProgress: (int sent, int total) {
print("$sent $total");
},
); |
is it possible to connect this upload progress with a steam to handle on our bloc part for displaying progress instead a callbak ? |
Ok, so I searched around and stumbled across this answer. StreamController<int> progressStreamController = new StreamController();
dio.get(
event.url,
onReceiveProgress: (received, total) {
progressStreamController.add(((received / total) * 100).round());
},
options: Options(
responseType: ResponseType.bytes,
followRedirects: false,
validateStatus: (status) {
return status < 500;
}),
).then((Response response) async {
//Do whatever you want with the response
}).whenComplete(() => progressStreamController.close());
await for (int p in progressStreamController.stream) {
yield DownloadingUpdate(progress: p);
} |
Where is from this Ok i use:
|
How about on uploading progress? |
@ariefwijaya From their docs it looks like you use the onSendProgress method in a POST request:
|
Hi! Thank you for creating this package, it's a lifesaver when it comes to generic multipart/formdata requests.
Is there a way to consume file upload progress event(s)?
Consider this a feature request, if it doesn't exist yet, or please point me in a direction if it's possible to implement
The text was updated successfully, but these errors were encountered: