簡體   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