简体   繁体   English

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

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

I'm currently uploading some data to firestore:我目前正在将一些数据上传到 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);
                    });

Images selected via Image_Picker, the question is how can I upload it to firebase using the method mentioned above.通过Image_Picker选择的图片,问题是如何使用上述方法上传到firebase。
PS: I'm a newbie to Flutter and Firebase stuff. PS:我是 Flutter 和 Firebase 的新手。

you can convert your image to base64 and give to the firebase which gives you the getDownloadURL .您可以将图像转换为 base64 并提供给 firebase ,它为您提供getDownloadURL That getDownloadURL should be saved somewhere so you can access it and show it into your flutter app.getDownloadURL应该保存在某个地方,以便您可以访问它并将其显示到您的 flutter 应用程序中。

I have a code snippet which you can refer it我有一个代码片段,你可以参考它

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;    
     });    
   });    
 }  

This is about a firebase real-time database.这是关于一个firebase的实时数据库。 if you need for firebase database then please let me know.如果您需要 firebase 数据库,请告诉我。

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

相关问题 使用 laravel 将图像上传到 Firestore - Upload image to firestore using laravel Flutter:使用 ImagePickerWeb 将图片上传到 Firestore - Flutter: Upload image to Firestore using ImagePickerWeb 如何在 firebase 存储中上传图像并使用 swr-firestore 在 React 中获取上传图像 url - how to upload image in the firebase storage and get uploaded image url in react using swr-firestore 如何上传图像 Url 上传到 Fire Storage 并同时将其保存在 fireStore 使用 Java - how to upload image Url Uploaded to Fire Storage and Save it in fireStore at the Same time Using Java 如何将图片正确上传到 Firebase 存储并保存到 firestore 的链接 - How to properly upload image to Firebase Storage and save link to firestore 如何将文档上传到 Firestore - How to upload documents to Firestore 使用 React 将图像上传到 firestore - upload images to firestore using react 如何通过Cloud Functions上传文件到Cloud Storage,并使用Firestore控制对Cloud Storage的访问? - How can I upload files to Cloud Storage through Cloud Functions and use Firestore to control access to Cloud Storage? 将多个文件上传到 Android 中的 firebase firestore - Upload multiple files to firebase firestore in Android 如何从 firebase 存储中获取图像 URL 列表并将其上传到云 firestore? - How to get a list of image URL from firebase storage and upload it to cloud firestore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM