backend is taking image as fileHere is my http post method where I had send data like title,link,description as string but when I tried to post image file it didn't work
void create(String title, link,description,File image) async {
try {
Response response = await post(
Uri.parse(NetworkConstants.BASE_URL + 'organization/opportunity'),
headers: {
"Authorization": "Bearer $token",
"Accept": "application/json"
},
body: {
'title': title,
'banner':Image.file(image),
'link': link,
'description':description
});
if (response.statusCode == 200) {
var data = jsonDecode(response.body.toString());
// print(data);
showToast(context, data['message']);
Navigator.pop(context);
} else {
var data = jsonDecode(response.body.toString());
showToast(context, data['errors'].toString());
}
} catch (e) {
print(e);
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Exception:"),
content: Text(e.toString()),
actions: [
TextButton(
child: Text("Try Again"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
}
} How to use multipart and send those fromdata also inside body