I'm trying to add cancel functionality to file upload in my Flutter app. I'm currently using http.MultipartRequest()
from http package
to upload the file. I've tried wrapping the upload with CancelableOperation
but it only cancels the internal process within my Flutter app and the file still gets uploaded successfully to my Firebase Storage server.
I read the README.md on http package about using http.Client()
and closing it after the http request is completed. I'm thinking about using http.Client()
to upload the file and then closing it with the http.Client().close()
to cancel the http request.
But, I haven't found the right way to upload file with http.Client
yet. I browsed about it on Google and stackoverflow but all the posts recommend using http.MultipartRequest()
. One of the posts
So, my questions are:
1. Is it possible to cancel upload file sent with http.MultipartRequest()
from http package in Flutter?
2. Am I in the right track with trying to use http.Client()
? Or is there any better way to do this?
3. If using http.Client()
is the only way, then can you please show me how to upload file with http.Client()
? since it only has post()
and no multipartrequest()
.
Sorry for the long text. Please help. Thanks!