tonMultiPart<S> method
Implementation
Future<NetResponse<S>> tonMultiPart<S>(
{required String url,
required Map<String, String> text,
File? file,
String? keyFile,
String? fileName}) async {
const boundary = '----BoundaryForMultipartRequest';
final closingBoundary = utf8.encode('\r\n--$boundary--\r\n');
final bodyBytes = <int>[];
text.forEach(
(key, value) {
bodyBytes.addAll(_buildTextBloc(boundary, key, value));
},
);
if (file != null && keyFile != null) {
final bytes = await _buildFileBloc(
boundary, keyFile, file, fileName ?? basename(file.path));
bodyBytes.addAll(bytes);
}
bodyBytes.addAll(closingBoundary);
final body = Uint8List.fromList(bodyBytes);
return post(url,
options: Options(method: "POST", headers: {
'Content-Type': 'multipart/form-data; boundary=$boundary',
'Content-Length': body.length.toString(),
}),
data: Stream.fromIterable([Uint8List.fromList(body)]))
.buildNetResponse();
}