// My IPv4 : 192.168.43.171
final String phpEndPoint = 'http://192.168.43.171/phpAPI/image.php';
final String nodeEndPoint = 'http://192.168.43.171:3000/image';
File file;
void _choose() async {
file = await ImagePicker.pickImage(source: ImageSource.camera);
// file = await ImagePicker.pickImage(source: ImageSource.gallery);
}
void _upload() {
if (file == null) return;
String base64Image = base64Encode(file.readAsBytesSync());
String fileName = file.path.split("/").last;
http.post(phpEndPoint, body: {
"image": base64Image,
"name": fileName,
}).then((res) {
print(res.statusCode);
}).catchError((err) {
print(err);
});
}
解锁Flutter开发新姿势,,系统掌握Flutter开发核心技术。
了解课程