【问题标题】:StorageException has occurred. Object does not exist at location. Storage FireBase发生了 StorageException。对象在该位置不存在。存储 FireBase
【发布时间】:2023-03-10 10:33:01
【问题描述】:

我想在 imageView 中显示图像,这就是我正在做的事情:我正在使用 FirebaseUI 来显示来自 FireBase Storage 的图像。

FirebaseStorage storageDisplayImg;
StorageReference storageRef;
private FirebaseAuth auth;



        storageDisplayImg=FirebaseStorage.getInstance();
        auth = FirebaseAuth.getInstance();
        FirebaseUser userConnect = auth.getCurrentUser();
        String id_user=userConnect.getUid();
        storageRef = storageDisplayImg.getReference().child(item.getChemin_image()); // return gs://mydreambook-32321.appspot.com/images/test23-03-2017_16:46:55

        if (item.getChemin_image() != null&&id_user != null) {

           Glide.with(convertView.getContext() )
                   .using(new FirebaseImageLoader())
                   .load(storageRef)
                   .into(profilePic);
            profilePic.setVisibility(View.VISIBLE);

        } else {
            profilePic.setVisibility(View.GONE);
        }

但我有这个错误:

StorageException has occurred.  Object does not exist at location.    Code: -13010 HttpResult: 404

更新,存储 FireBase 中的图像

【问题讨论】:

  • 使用 Firebase 控制台确认有图像存储在位置 gs://myApp.appspot.com/images/sport23-03-2017_15:22:54
  • 请检查更新@BobSnyder
  • item.getChemin_image() 是返回完整字符串“gs://myApp.appspot.com/images/sport23-03-2017_15:22:54”还是只返回“images/sport23-03” -2017_15:22:54”?如果它返回前者你实际上想要做storageDisplayImg.getReferenceFromUrl(item.getChemin_image())(它需要完整的URL)。
  • 它有效,谢谢@MikeMcDonald

标签: android firebase firebase-storage


【解决方案1】:

我现在遇到了同样的问题,我意识到我在存储中的图像以 .jpg 结尾,但我的代码要求以 .png 结尾的地址。在我修复它之后,它对我来说运行完美。

【讨论】:

  • 它拯救了我一整天。谢谢
【解决方案2】:

您可以使用 Glide 方法以两种方式简单地显示图像。如果我们想访问下面的方法,我们必须更改 Firebase 存储规则。在这里我包括了我的规则。

service firebase.storage {
  match /b/project-id.appspot.com/o {
    match /{allPaths=**} {
      allow write: if request.auth != null;
      // or allow write: if true;
    }
  }
} 

方法一。 只需使用 Firebase 参考

FirebaseStorage storage = FirebaseStorage.getInstance();
                StorageReference storageRef = storage.getReferenceFromUrl("gs://your-id.appspot.com");
                StorageReference pathReference = storageRef.child("images/cross.png");

                Glide.with(context)
                        .using(new FirebaseImageLoader())
                        .load(pathReference)
                        .into(Imageview)

方法 2. Firebase 网址

     Glide.with(context)
             .using(new FirebaseImageLoader())
             .load("Firebase_ImageURL")
             .into(Imageview)

【讨论】:

  • 方法 2 不起作用。 Glide 中不再有“使用”。
【解决方案3】:

嗨,我两天前遇到了这样的问题。存储异常通常发生在您在 Firebase 启动之前使用谷歌开发者控制台创建的项目中。 所以当我将我的应用程序连接到 Firebase 上的现有项目时,它就可以工作了。要确认您的项目是否接受存储,请转到 Firebase 控制台并在左键单击存储,如果您显示有文件上传选项,则该项目能够存储,否则不能存储。

【讨论】:

  • 请以可读的形式编辑您的评论。很难阅读
【解决方案4】:

好的,当我知道我必须提供图像的完整路径时,我找到了解决方案

 storageReference.child("users").child(userID).child("screenshot")
                .child(imagePath).getFile(localFile)

我最初给出的路径不完整

 storageReference.child("users").child(userID).child("screenshot").getFile(localFile)
              

【讨论】:

    【解决方案5】:

    我遇到了类似的问题。我试图删除包含错误大小写字母的文件

    示例:通过搜索file_of_user_uIdAbCdE.png删除file_of_user_uidabcde.png

    【讨论】:

      【解决方案6】:

      您可以尝试在图片上传和图片恢复之间等待一段时间。这对我的问题很有效。祝你好运。

      【讨论】:

        【解决方案7】:

        在我的例子中,我将完整的 URL 保存在 Firebase 数据库中并像这样获取它:gs: //your-id.appspot.com/images/cross.png

        当我这样做时:

        StorageReference ref = FirebaseStorage().Ref().Child(urlImag);
              url = (await ref.getDownloadURL()).toString();
        

        我正在做以下事情:

        StorageReference ref = FirebaseStorage (gs://your-id.appspot.com/images/cross.png).ref().child ();
              url = (await ref.getDownloadURL()).toString();
        

        如果您的字段中已经保存了完整的 URL,则无需执行此步骤。

        【讨论】:

          【解决方案8】:

          我使用的是不同的 Firebase 项目,然后我创建了一个新项目。当我添加 google-services.json 并尝试在存储中添加照片时,我发生了这个错误。当我调试我的项目时,我发现我的存储参考显示旧网址(gs://oldproject.appspot.com)。我在 Android 项目中搜索了 appspot.com 并看到了 values.xml 文件。使用新的 firebase 项目 ID 更改 values.xml 文件内容,然后存储工作。

          【讨论】:

            【解决方案9】:

            如果遇到 404 错误,请检查存储规则:

            service firebase.storage {
              match /b/{bucket}/o {
                match /{allPaths=**} {
                  allow read, create: if request.auth != null;
                }
              }
            }
            

            【讨论】:

              猜你喜欢
              • 2021-12-29
              • 1970-01-01
              • 2020-04-17
              • 2020-08-02
              • 2019-04-07
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2023-03-31
              相关资源
              最近更新 更多