sendFiles method
Future<String>
sendFiles(
- HttpMethod method,
- String path,
- List<
String> fields, - List<
String> filePaths, { - ProcessStreamedResponseMethod? processStreamedResponseMethod,
- Map<
String, String> ? queryParameters, - Map<
String, String> ? headers, - String? authority,
- bool headersReplace = false,
- bool queryParametersReplace = false,
- bool? useSSL,
Implementation
Future<String> sendFiles(
HttpMethod method,
String path,
List<String> fields,
List<String> filePaths, {
ProcessStreamedResponseMethod? processStreamedResponseMethod,
Map<String, String>? queryParameters,
Map<String, String>? headers,
String? authority,
bool headersReplace = false,
bool queryParametersReplace = false,
bool? useSSL,
}) async {
final _queryParameters = <String, String>{};
if (!queryParametersReplace) {
_queryParameters.addAll(this.queryParameters);
}
_queryParameters.addAll(queryParameters ?? {});
final uri = (useSSL ?? this.useSSL)
? Uri.https(authority ?? this.authority, path, _queryParameters)
: Uri.http(authority ?? this.authority, path, _queryParameters);
final request = http.MultipartRequest(method.name, uri);
if (!headersReplace) request.headers.addAll(this.headers);
request.headers.addAll(headers ?? {});
if (debug) {
final func = logFunction ?? dev.log;
func(
'Request $method.name: $uri\n\t\t'
'${request.headers.isNotEmpty ? 'Headers: $request.headers\n\t\t' : ''}',
);
}
final length = min(filePaths.length, fields.length);
for (var i = 0; i < length; ++i) {
final file = await http.MultipartFile.fromPath(fields[i], filePaths[i]);
request.files.add(file);
}
final response = await request.send();
final body = utf8.decode(await response.stream.toBytes());
if (debug) {
printResponse(
method: method.name,
path: path,
statusCode: response.statusCode,
data: body,
logFunction: logFunction,
);
}
if (processStreamedResponseMethod != null) {
await processStreamedResponseMethod(response);
} else {
await _processStreamedResponseMethod(response);
}
return body;
}