I'm trying to post image and data but I'm getting this error plz help. I'm using dio: ^3.0.9. Works perfectly fine in postman And if I remove the image from data and post just the data it works fine.

class ProfileRepository {
  LocalStorage localStorage = new LocalStorage();
  Dio dio = new Dio();

  final url = 'http://localhost:3000/api/profile';

  Future<ProfileModel> getProfileResponse(
      String fullName,
      String position,
      String gender,
      String homeAddress,
      String officeAddress,
      String phoneNumber,
      File image) async {
    final token = await localStorage.getLoginToken();
    final splitToken = token.split(' ');
    final finalToken = splitToken[1];

    String imageFile = image.path.split('/').last;
    var formData = new FormData.fromMap({
      "fullname": fullName,
      "position": position,
      "gender": gender,
      "home_address": homeAddress,
      "office_address": officeAddress,
      "phone_no": phoneNumber,
      "image": await MultipartFile.fromFile(image.path, filename: imageFile),
    });

    final response = await dio.post(url,
        data: formData,
        options: Options(headers: {'Authorization': finalToken}));

    if (response.statusCode == 201) {
      return ProfileModel.fromJson(json.jsonDecode(response.data));
    } else {
      throw Exception("Error");
    }
  }
}


Solution 1: Zero Live

final url = 'http://localhost:3000/api/profile';

Future<ProfileModel> getProfileResponse( String fullName, String position, String gender, String homeAddress, String officeAddress, String phoneNumber, File image) async { final token = await localStorage.getLoginToken(); final splitToken = token.split(' '); final finalToken = splitToken[1];

String imageFile = image.path.split('/').last;
FormData formData() {
 var formData = new FormData.fromMap({
  "fullname": fullName,
  "position": position,
  "gender": gender,
  "home_address": homeAddress,
  "office_address": officeAddress,
  "phone_no": phoneNumber,
});
  formData.files.addAll([
      MapEntry(
          "files",
          MultipartFile.fromFileSync(image.path, filename: imageFile)),
  ]);
  return formData;
}
final response = await dio.post(url,
    data: formData(),
    options: (contentType: 'multipart/form-data', headers: {
    "Accept": "application/json",
    "Authorization": finalToken,
  }),
););

if (response.statusCode == 201) {
  return ProfileModel.fromJson(json.jsonDecode(response.data));
} else {
  throw Exception("Error");
}

} }

Try this. If I had to guess, I think it's issue with your image path.