api - 使用 Flutter 将带有图像的数据发送(发布)到 RestFull API
问题描述
我如何在颤动中将带有图像 url 的数据发送到 RestFull API,这是我的代码,但它不起作用,问题只是因为图像和所有数据发送成功:
String imgUrl;
insertService() async {
var res = await http.post(
"http://192.168.43.106:3000/service",
headers: {},
body: {
"name" : namec.text,
"file" : imgUrl,
"desc" : descc.text,
"price" : pricec.text,
"cat" : widget.cid
}
);
final data = json.decode(res.body);
if(data['message'] != null && data['message'] == 'success'){
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context)=>Services(cid: widget.cid,)));
}else{
print("there is a problem in post request....");
}
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
final img = Padding(
padding: EdgeInsets.all(20),
child: InkWell(
onTap: ()async{
var imageIns = await ImagePicker().getImage(source: ImageSource.gallery);
setState(() {
image = File(imageIns.path);
imgUrl = imageIns.path;
});
解决方案
的确切类型是imageIns.path
什么?如果它是一个对象,您可能需要将其编码为 json。
推荐阅读
- c# - 使用 Linq 在 EF-Core 中进行 INNER Join 和 LEFT OUTER JOIN
- asp.net - ASP.NET 中继器按数据分组
- ios - iOS / Swift中的CVPixelBuffer到RGBA缓冲区?
- ios - 让 VoiceOver 说“向上或向下滑动以选择自定义操作,然后双击以激活”
- css - adobe xd 插件中的 Flexbox 布局问题
- excel - APEX office print Plugin - 如何在模板中获取下载日期/创建日期
- java - Spring Boot 1.5.x 与 Java 11 的兼容性
- c - 探索 getchar() 函数
- java - Settings Activity Android 方法无法从静态内容中引用
- javascript - 如何为所有其他客户端移动特定客户端 div 他的鼠标位置