flutter http send jpg code example
Example: flutter http send jpg
var stream =
new http.ByteStream(DelegatingStream.typed(imageFile.openRead()));
var length = await imageFile.length();
Map<String, String> headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token
};
var uri = Uri.parse(Constants.BASE_URL + "api endpoint here");
var request = new http.MultipartRequest("POST", uri);
var multipartFileSign = new http.MultipartFile('profile_pic', stream, length,
filename: basename(imageFile.path));
request.files.add(multipartFileSign);
request.headers.addAll(headers);
request.fields['loginId'] = '12';
request.fields['firstName'] = 'abc';
var response = await request.send();
print(response.statusCode);
response.stream.transform(utf8.decoder).listen((value) {
print(value);
});