httpApiMultipartPost function
origin: simlpu_mob/lib/globals.dart union-of: kt_ifm_gtid_mob/lib/global.dart, stm_portal_mob/lib/global.dart author: anovsiradj, opencode-go/glm-5.2 version: 2022-01-28, revised: 2026-08-17
Multipart POST. fileParams values: File (from path) or MultipartBytesFile (in-memory bytes).
If config.methodSpoofing and spoofMethod provided, appends _method=<SPOOF> to fields.
Implementation
Future<http.StreamedResponse> httpApiMultipartPost(
String suffixUrl, {
Map<String, dynamic>? fileParams,
Map<String, dynamic>? postParams,
Map<String, dynamic>? getParams,
String? spoofMethod,
SkitHttpConfig? config,
}) async {
final cfg = config ?? defaultConfig;
final httpUri = Uri.parse(cfg.baseUrl + suffixUrl).replace(queryParameters: _mergeParams(getParams, cfg));
_debugLog('[httpApiMultipartPost] $httpUri');
final req = http.MultipartRequest('POST', httpUri);
req.fields.addAll({
...?postParams?.map((k, v) => MapEntry(k, v?.toString() ?? '')),
if (cfg.methodSpoofing && spoofMethod is String) '_method': spoofMethod.toUpperCase(),
});
await Future.wait(fileParams?.entries.map((e) async {
final v = e.value;
if (v is File) {
final mime = lookupMimeType(v.path)?.split('/');
if (mime != null) {
req.files.add(await http.MultipartFile.fromPath(
e.key,
v.path,
filename: path.basename(v.path),
contentType: http_parser.MediaType(mime[0], mime[1]),
));
}
}
if (v is MultipartBytesFile) {
req.files.add(http.MultipartFile.fromBytes(e.key, v.file, filename: v.filename, contentType: v.contentType));
}
}) ?? <Future>[]);
return req.send().timeout(cfg.timeout);
}