uploadFile static method

Future<String> uploadFile(
  1. String url, {
  2. Map<String, String>? headers,
  3. String imagePath = '',
  4. String fieldName = '',
})

Implementation

static Future<String> uploadFile(String url,
    {Map<String, String>? headers,
    String imagePath = '',
    String fieldName = ''}) async {
  var reqHeaders = await getHeaders(customHeaders: headers);

  var request = http.MultipartRequest("POST", Uri.parse(url));
  var pic = await http.MultipartFile.fromPath(fieldName, imagePath);
  request.files.add(pic);
  request.headers.addAll(reqHeaders);
  var response = await request.send();

  String responseString = await response.stream.bytesToString();
  return responseString;
}