multipartRequest method

Future<StreamedResponse> multipartRequest(
  1. String endpoint,
  2. File fileAsset,
  3. String fileFieldName,
  4. String? fileName,
  5. Map<String, dynamic>? body,
  6. String? token, {
  7. ApiType apiType = ApiType.POST,
})

Make an API post multipart form call

! Do not support mockClient

Implementation

Future<http.StreamedResponse> multipartRequest(
    String endpoint, File fileAsset, String fileFieldName, String? fileName, Map<String, dynamic>? body, String? token,
    {ApiType apiType = ApiType.POST}) async {
  String currentApiType = this.apiType(apiType);
  var request = http.MultipartRequest(currentApiType, Uri.parse(endpoint));
  if (token != null) {
    Map<String, String> customHeaders = {this.headerAuthKey: token};
    request.headers.addAll(customHeaders);
  }
  request.files.add(http.MultipartFile.fromBytes(fileFieldName, fileAsset.readAsBytesSync(), filename: fileName));
  return request.send();
}