send method

Future<StreamedResponse> send(
  1. MultipartRequest request
)

Sends an generic HTTP MultipartRequest with the given headers to the given URL, which can be a Uri or a String.

Implementation

Future<http.StreamedResponse> send(http.MultipartRequest request) async {
  http.MultipartRequest sending = request;

  return await retry(
    () => client.send(sending).timeout(const Duration(seconds: 5)),
    delayFactor: const Duration(seconds: 25),
    maxAttempts: 15,
    retryIf: (e) => e is SocketException || e is TimeoutException,
    onRetry: (e) {
      print('${e.runtimeType} - Retrying to SEND ${request.url}');

      // when retrying sending form data, the request needs to be cloned
      // see e.g. >> https://github.com/flutterchina/dio/issues/482
      sending = http.MultipartRequest(request.method, request.url);
      sending.headers.addAll(request.headers);
      sending.fields.addAll(request.fields);

      for (var file in request.files) {
        if (file is ClonableMultipartFile) {
          sending.files.add(file.clone());
        }
      }
    },
  );
}