Firebase存储桶名称不可用 [英] Firebase Bucketname Not Available

查看:118
本文介绍了Firebase存储桶名称不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android中使用Firebase遇到了一个奇怪的问题.我正在尝试将照片上传到Firebase Storage,但出现以下错误:

I'm having a weird problem with Firebase in Android. I'm trying to upload a photo to Firebase Storage and I'm getting the following error:

E/UncaughtException: java.lang.IllegalArgumentException: The supplied bucketname is not available to this project.

此行代码:

StorageReference mStorageRef = mFirebaseStorage.getReferenceFromUrl("gs://mooseandroid-a9f96.appspot.com");

我确定存储桶名称与控制台中的相同.我什至尝试使用在iOS上使用Swift可以正常工作的存储桶名称.我还将规则更改为公开,因此任何人都可以对该存储桶进行读写.实时数据库可以很好地完成该项目.我现在用光了所有选项,甚至不知道我还能尝试什么.

I'm sure that the bucketname is the same as the one in the console. I even tried with a bucketname that works fine in iOS with Swift. I also changed the rules to public so anyone can read and write to this storage bucket. The realtime database works fine for this project. I'm running out of options right now, don't even know what else I could be trying.

这是整个代码段:

FirebaseStorage mFirebaseStorage = FirebaseStorage.getInstance();
StorageReference mStorageRef = mFirebaseStorage.getReferenceFromUrl("gs://mooseandroid-a9f96.appspot.com");
final StorageReference photoRef = mStorageRef.child("posts_images/mooseImg" + getCurrentDateTime() + ".jpg");
UploadTask uploadTask = photoRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
    // Handle unsuccessful uploads
    }
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
    // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
});

这是整个错误:

E/UncaughtException: java.lang.IllegalArgumentException: The supplied bucketname is not available to this project.
     at com.google.android.gms.common.internal.zzaa.zzb(Unknown Source)
     at com.google.firebase.storage.FirebaseStorage.zzz(Unknown Source)
     at com.google.firebase.storage.FirebaseStorage.getReferenceFromUrl(Unknown Source)
     at com.moose.android.AddPostActivity.onClick(AddPostActivity.java:163)
     at android.view.View.performClick(View.java:5702)
     at android.widget.TextView.performClick(TextView.java:10888)
     at android.view.View$PerformClick.run(View.java:22541)
     at android.os.Handler.handleCallback(Handler.java:739)
     at android.os.Handler.dispatchMessage(Handler.java:95)
     at android.os.Looper.loop(Looper.java:158)
     at android.app.ActivityThread.main(ActivityThread.java:7229)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

推荐答案

如果fullUrl与FirebaseApp没有关联,则会引发错误 用于初始化此FirebaseStorage

An error is thrown if fullUrl is not associated with the FirebaseApp used to initialize this FirebaseStorage

使用此代码在您的FirebaseApp中查看存储桶名称:

Use this code to see the bucket name in your FirebaseApp:

    FirebaseOptions opts = FirebaseApp.getInstance().getOptions();
    Log.i(TAG, "Bucket = " + opts.getStorageBucket());

我希望它不是mooseandroid-a9f96.appspot.com,而是google-services.json文件的project_info部分中的storage_bucket值:

I expect it will not be mooseandroid-a9f96.appspot.com and will instead be the storage_bucket value in the project_info section of your google-services.json file:

  "project_info": {
    "project_number": "816275527980",
    "firebase_url": "https://project-8693710910123456789.firebaseio.com",
    "project_id": "project-8693710910123456789",
    "storage_bucket": "project-8693710910123456789.appspot.com"
  },

这篇关于Firebase存储桶名称不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆