firebase - 如何在颤动中将图像临时存储在文件中?
问题描述
我想临时存储图像并获取文件路径,因此我可以将图像存储在 firebase 中,然后删除临时文件。我看到一些帖子将文件中的图像保存为字节。但是我将如何将它保存在 Firebase 存储中呢?有什么建议么?
Container(
child: SfSignaturePad(
key: _signaturePadKey,
minimumStrokeWidth: 1,
maximumStrokeWidth: 3,
strokeColor: Colors.blue,
backgroundColor: Colors.grey,
),
height: 200,
width: 300,
),
Row(
children: [
Text('clear image', style: kTextFieldReg,),
SizedBox(height:4, width: 4 ),
IconButton(onPressed: ()
async {
_signaturePadKey.currentState.clear();
// Navigator.push(context, MaterialPageRoute(
// builder: (context) => ScreenTwo()));
}, icon: CircleAvatar(
backgroundColor: Color(0xff660B21),
radius: 19,
child: ClipOval(
child:Icon((Icons.close), color: Colors.white, ))
)) ]
),
SizedBox(width: 20, height: 20,),
ElevatedButton(
child: Text(
'Add',
style: TextStyle(color: Colors.white),
),
style: ElevatedButton.styleFrom(
minimumSize: Size(150, 60), primary: Color(0xff660B21),),
onPressed: () async{
// NEED TO STORE THIS IMG TEMPORARILY ANS GET ITS FILE PATH
ui.Image image = await _signaturePadKey.currentState.toImage(pixelRatio: 3);
if (_formKey.currentState.validate()) ...
解决方案
当您将文件保存到临时文件时,您只需要获取path
文件和以下代码:
Future<void> uploadFile(String filePath) async {
File file = File(filePath);
try {
await firebase_storage.FirebaseStorage.instance
.ref('uploads/file-to-upload.png')
.putFile(file);
} on firebase_core.FirebaseException catch (e) {
// e.g, e.code == 'canceled'
}
}
有关如何将文件保存到临时路径的更多详细信息,我们需要您提供更多信息。上面的代码应该是将文件从路径上传到 firebase 存储的部分。
推荐阅读
- powershell - 合并脚本并更新 csv 文件
- python - 用于计算 groupby 百分比的 Pandas Window 函数
- python - code=H10 desc="App 崩溃" Heroku 应用程序错误
- amazon-web-services - 如何在侦听 cognito PreSignUp 事件的不同微服务中执行多个 lambda?
- angular - 角度路由器总是将我重定向到/#/
- r - 数据表的连续行之间的R快速余弦距离
- flutter - Dart 未处理的异常:键入“列表”
' 不是类型 'Family' 的子类型,- Flutter - spring - SpringBoot 遇到 APPLICATION FAILED TO START 错误
- javascript - 我希望搜索框从所有页面中消失,除了带有 React.js 的产品页面
- kotlin - 如何让 Kotlin 在非主构造函数中使用字段而不是 setter