uploadFile static method

Future<Response> uploadFile(
  1. PlatformFile file
)

Implementation

static Future<Response> uploadFile(PlatformFile file) async {
  //Converting Platformfile to File
  File fileToSend = File(file.path!);
  //Converting file to bytes
  List<int> imageBytes = fileToSend.readAsBytesSync();
  //Converting bytes to Base64
  String base64Image = base64Encode(imageBytes);
  var requestBody = {
    "fileName": 'EXTERNAL/${file.name}',
    "fileData": base64Image
  };
  //Waiting for response while is sent as an Http Post
  var response = await ApiManager.post(SocketUrls.baseFileUploadEndpoint,
      body: jsonEncode(requestBody));
  return response;
}