I am trying to create a http.post request that sends an image file along with text. I think that I am only sending a partial request to the server and its getting rejected. I have tried this in MultiPartForm and in the method below
I have tried to create the post request but, I get this error: Unhandled Exception: type '_File' is not a subtype of type 'String' in type cast
void createPreferences(
String phone,
String nickName,
String customerType,
double age,
File currentSelfie) {
//Variables
var uri = Uri.http('10.0.2.2:8000', '/api/customer/create_customer_details/', params);
var params = {
'access_token': _accessTkn,
};
final Map<dynamic, dynamic> custPreferences = {
'phone': phone,
'nick_name': nickName,
'customer_type': customerType,
'age': '${'age'}',
};
var request = http.MultipartRequest("POST", uri,);
var multipartFile = new http.MultipartFile('current_selfie', stream, length,
filename: basename(currentSelfie.path));
request.files.add(multipartFile);
var response = await request.send();
print(response.statusCode);
response.stream.transform(utf8.decoder).listen((value) {
print(value);
});
}
final Map<String, dynamic> responseData = json.decode(response.body);
print(responseData);
print('Response body: ${response.body}');
});
}
I want to create this request and verify that I data is accepted by my server.