avatarUpload(file) async { FormData formData = FormData.fromMap({ "file": await MultipartFile.fromFile(file.path, filename: "xxx23.png") }); var result = await requestApi.filesupload1(formData); if (result['code'] == 200) { setState(() { headimg = 'file' + result['data']['path']; }); Fluttertoast.showToast( msg: '上传成功', toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, ); }
折腾了一天终于搞定了图片上传,接口一直报找不到file 一开始直接把函数获取的file传给file,就是不行,最后使用了await MultipartFile.fromFile(file.path, filename: "xxx23.png") 才成功上传了,不是太明白原理,不过功能实现了