postAPI method
Implementation
Future<BaseResponse> postAPI(String url, String method, data,
{hasHeader = true, Map<String, String>? body, List<dynamic>? realFiles,
List<String>? files, String paramFile = 'file', int timeout = 20}) async {
final baseResponse = BaseResponse();
try {
final request = http.MultipartRequest(method, Uri.parse(baseUrl + url));
request.headers.addAll(await _getHeader(hasAuthen: hasHeader));
if (body != null) request.fields.addAll(body);
if (files != null) {
for (String path in files) {
request.files.add(_createPartFile(File(path), paramFile));
}
} else if (realFiles != null) {
for (var file in realFiles)
request.files.add(_createPartFileByte(file, paramFile));
}
final streamResponse = await request.send().timeout(Duration(seconds: timeout));
final response = await http.Response.fromStream(streamResponse);
baseResponse.fromJson(jsonDecode(response.body), data);
} catch (e) {
return _responseError(baseResponse, e);
}
return baseResponse;
}