flutter cancel MultipartRequest upload

Viewed 18

i'm using MultipartRequest to upload videos file in my app, and i want to add the cancel functionality of the upload anywhere from the app, so i'm asking if there is a way to check for multipartRequests running in the app and cancel it from an opened dialog for exemple. here is my code for uploading :

          MultipartRequest('POST', Uri.parse(newPost));
      secondRequest.headers.addAll({
        authorization: await SessionManager().getBearerJWT(),
        contentType: multipartFormData
      });
      secondRequest.fields.addAll({
        "message": message,
        "entitiesList": "[]",
        "tagsList": '',
        "rawMessage": message,
        "mediaType": 'Video',
        "isPrivate": 'false',
      });
      StreamedResponse res = await secondRequest.send();
      String resBody = await res.stream.bytesToString();
      var postResponse = jsonDecode(resBody);
0 Answers
Related