I'm trying to upload an image through the flutter via post method. and I'm using image\_picker for pick file from mobile but I can't able to upload

and I have tried to send the file like FormData that also doesn't work

```
      Future<dynamic> uploadLicence(int id ,dynamic obj) async {
          FormData formdata = new FormData(); // just like JS
          formdata.add("image",obj); 
          final response = await post('Logistic/driver/LicenceImage? 
          driverId=$id', 
          formdata);
          print(response);
         //  return null;
     if (response.statusCode == 200) {
         final result = json.decode(response.body);
         return result;
    } else {
          return null;
   }
   }

```

after that, I just tried with this method but this also not working 

```
   Future<dynamic> uploadLicence(int id, File file) async {
   final url = Uri.parse('$BASE_URL/Logistic/driver/LicenceImage? 
   driverId=$id');
   final fileName = path.basename(file.path);
   final bytes = await compute(compress, file.readAsBytesSync());

   var request = http.MultipartRequest('POST', url)
   ..files.add(new http.MultipartFile.fromBytes(                                                     
  'image',bytes,filename: fileName,);
  var response = await request.send();
  var decoded = await 
  response.stream.bytesToString().then(json.decode);
  if (response.statusCode == HttpStatus.OK) {
  print("image uploded $decoded");
  } else {
   print("image uplod failed ");
  }
  }

             List<int> compress(List<int> bytes) {
             var image = img.decodeImage(bytes);
             var resize = img.copyResize(image);
            return img.encodePng(resize, level: 1);
            }

```