繁体   English   中英

如何使用 crud 方法将图像文件上传到 FIRESTORE?

[英]How to upload image files to FIRESTORE using crud method?

我目前正在将一些数据上传到 firestore:

 Map<String, dynamic> ads = {
                      'adTitle': widget.title,
                      'adPrice': widget.price,
                      'adCategory': widget.dropdownValue,
                      'adCondition': this.newCondtionVal,
                      'adDesc': widget.desc,
                      'user_id': uID,
                    
                      ///TODO upload the images.
                    };
                    crudObj
                        .addData(ads)
                        .then((value) => {
                              showInSnackBar("dataAdded"),
                            })
                        .catchError((e) {
                      print(e);
                    });

通过Image_Picker选择的图片,问题是如何使用上述方法上传到firebase。
PS:我是 Flutter 和 Firebase 的新手。

您可以将图像转换为 base64 并提供给 firebase ,它为您提供getDownloadURL getDownloadURL应该保存在某个地方,以便您可以访问它并将其显示到您的 flutter 应用程序中。

我有一个代码片段,你可以参考它

Future uploadFile() async {    
   StorageReference storageReference = FirebaseStorage.instance    
       .ref()    
       .child('chats/${Path.basename(_image.path)}}');    
   StorageUploadTask uploadTask = storageReference.putFile(_image);    
   await uploadTask.onComplete;    
   print('File Uploaded');    
   storageReference.getDownloadURL().then((fileURL) {    
     setState(() {    
       _uploadedFileURL = fileURL;    
     });    
   });    
 }  

这是关于一个firebase的实时数据库。 如果您需要 firebase 数据库,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM