postMethodsForUploadBill static method

Future postMethodsForUploadBill(
  1. String url,
  2. File imageFile
)

Implementation

static Future<dynamic> postMethodsForUploadBill(String url, File imageFile) async {
  var request = http.MultipartRequest('POST', Uri.parse(url));
  var headers = {
    'content-type': 'multipart/form-data',
    //'Authorization': token
  };
  //request.files.add(await http.MultipartFile.fromPath('file', imagePath));
  request.files.add(http.MultipartFile('file', imageFile.readAsBytes().asStream(), imageFile.lengthSync(),
      filename: imageFile.path.split("/").last, contentType: MediaType('image', 'jpeg')));
  request.headers.addAll(headers);
  try {
    var streamedResponse = await request.send();
    var response = await http.Response.fromStream(streamedResponse);
    if (streamedResponse.statusCode == 200) {
      return response;
    } else {
      var jsonString = ErrorResponse.responseData(response);
      return jsonString;
    }
  } catch (e) {
    rethrow;
  }
}