upload method

Future<T> upload({
  1. required TGUploadRequest request,
  2. dynamic onSuccess(
    1. dynamic T
    )?,
  3. dynamic onError(
    1. dynamic T
    )?,
})

Implementation

Future<T> upload(
    {required TGUploadRequest request, onSuccess(T)?, onError(T)?}) async {
  try {
    var multipartRequest = http.MultipartRequest(
        "POST",
        Uri.parse(TGRequest.prepareUrl(
            TGRequest.defaultBaseUrl, request.getUri())));
    multipartRequest.files.add(request.file());
    StreamedResponse httpRes = await multipartRequest.send();
    return _performCallbackForStreamedResponse(httpRes, onError, onSuccess);
  } catch (error) {
    T t = _populateExceptionResponse(error);
    onError!(t);
    return t;
  }
}