Flutter 如何进行图片选择与上传?
来源:6-16 拍照APP开发-图片获取与图片展示【实战尝鲜】
CrazyCodeBoy
2019-12-16
- 图片选择用:https://pub.dev/packages/image_picker
- 图片上传:
// 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);
});
}
写回答
1回答
-
CrazyCodeBoy
提问者
2019-12-16
如上。
20
相似问题
flutter 图表
回答 1