简体   繁体   English

将文件上传到 firebase 存储和云 firebase 时创建 2 个不同的 url

[英]2 different urls created while uploading files to firebase storage and cloud firebase

Iam uploading files to firebase storage and the referenced url in cloudfirestore.我将文件上传到 firebase 存储和 cloudfirestore 中引用的 url。 Uploading and showing the file in the app works perfectly.在应用程序中上传和显示文件效果很好。 But when i try to delete an image, i get an error: "[firebase_storage/object-not-found] No object exists at the desired reference."但是,当我尝试删除图像时,出现错误:“[firebase_storage/object-not-found] No object 存在于所需的参考中。” I found out that the urls in firebasestorage and in cloudfirestore are not the same:我发现firebasestorage和cloudfirestore中的url不一样:

FirebaseStorage URL: https://firebasestorage.googleapis.com/v0/b/project-db68d.appspot.com/o/images%2FNvbKO7fZxv5KXsPy1lPJovsxiKXN%2Fimage_cropper_1662715164516_out.jpg?alt=media&token=2d591f0d-d2ee-4640-8133-57cea509d3d7 //Does not show the file in the browser FirebaseStorage URL: https://firebasestorage.googleapis.com/v0/b/project-db68d.appspot.com/o/images%2FNvbKO7fZxv5KXsPy1lPJovsxiKXN%2Fimage_cropper_1662715164516_out.jpg?alt=media&token=2d591f0d-d2ee-4640-8133-57cea509d3d7 //不在浏览器中显示文件

CloudFirestore URL: gs://project-db68d.appspot.com/images/NvbKO7fZxv5KXsPy1lPJovsxiKXN/image_cropper_1662715164516_out.jpg // Shows the file in der browser CloudFirestore URL: gs://project-db68d.appspot.com/images/NvbKO7fZxv5KXsPy1lPJovsxiKXN/image_cropper_1662715164516_out.jpg // 在浏览器中显示文件

I don`t understand why 2 different urls are created and how to fit it, when i print the url it shows the url from firestorage?我不明白为什么要创建 2 个不同的 url 以及如何适应它,当我打印 url 时,它显示来自 firestorage 的 url?

This is my code: Iam working with ImagePicker, flutter_image_compress and image_cropper, latest versions flutter and packages这是我的代码:我正在使用 ImagePicker、flutter_image_compress 和 image_cropper、最新版本 flutter 和软件包

Future<File?> getImageFromCamera()async{
  File receivedImageFromCamera = await _pickImageFromDevice.pickSingleImageFromGallerieOrCamera(ImageSource.camera);
  File receivedCroppedImage = await _croppImageFromDevice.imageCropper(receivedImageFromCamera);
  File? compressedFile = (await _imageCompressor.compressFile(receivedCroppedImage));
  return compressedFile;
}

static Future<String> uploadFile(String destination,File file)async{
  final ref = FirebaseStorage.instance.ref(destination);
  final result = await ref.putFile(file);
  final String fileUrl = (await result.ref.getDownloadURL()).toString();
  return fileUrl;
}


   if(compressedFile==null) return;
  final fileName = basename(compressedFile.path);
  final destination = 'images/$chatId/$fileName';
  final fileUrl = await UploadFileToStorage.uploadFile(destination,compressedFile);

Both URLs are valid references to the file, but they have a different protocol.这两个 URL 都是对该文件的有效引用,但它们具有不同的协议。 The gs:// protocol is specific to Google Cloud Storage, and is supported by very few clients. gs://协议特定于谷歌云存储,很少有客户端支持。 The https:// protocol is universal and supported almost everywhere. https://协议是通用的,几乎在所有地方都受支持。

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

相关问题 将文件从 Firebase 云函数上传到云存储 - Uploading files from Firebase Cloud Functions to Cloud Storage 获取firebase存储中多个文件的下载地址 - Get the download URLs of multiple files in firebase storage 在 firebase 存储中一次上传多张照片并将它们的 URL 存储在 firestore 文档中(firebase 版本 9) - Uploading multiple photos at once in firebase storage and storing their URLs in a firestore document (firebase version 9) 上传文件到firebase存储Flutter后无法获取下载链接 - Cannot get the download link after uploading files to firebase storage Flutter 将文件上传到 android 的 firebase 存储中的用户特定目录? - Uploading files to user specific directories in firebase storage for android? Firebase 云存储 - Unity - PutStreamAsync memory 大文件崩溃 - Firebase Cloud Storage - Unity - PutStreamAsync memory crash with large files Firebase:云存储高带宽 - Firebase: cloud storage high bandwith 读取多个 Firebase 存储 URL 到阵列时出现问题 - Problem reading multiple Firebase Storage URLs to array 在 vue 3 中安装 firebase - 未创建文件 - Installing firebase in vue 3 - no files created Firebase-tools 没有将新创建的函数上传到 Firebase - Firebase-tools is not uploading newly created functions to Firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM