uploadFile method

Future<T> uploadFile({
  1. required TGUploadFileRequest request,
  2. dynamic onSuccess(
    1. dynamic T
    )?,
  3. dynamic onError(
    1. dynamic E
    )?,
})

Implementation

Future<T> uploadFile(
    {required TGUploadFileRequest request,
    onSuccess(T)?,
    onError(E)?}) async {
  try {
    var multipartRequest = http.MultipartRequest(
        "POST",
        Uri.parse(TGRequest.prepareUrl(
            TGRequest.defaultBaseUrl, request.getUri())));
    multipartRequest.headers.addAll(request.headers()!);
    multipartRequest.fields.addAll(request.body());
    multipartRequest.files.addAll(request.files());
    StreamedResponse httpRes = await multipartRequest.send();
    return _performCallbackForUploadFileResponse(httpRes, onError, onSuccess);
  } catch (error) {
    T t = _populateExceptionResponse(error);
    onError!(t);
    return t;
  }
}