[英]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.