Firebase Bucketname Not Available

*爱你&永不变心* 提交于 2020-01-14 02:32:54

问题


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.

At this line of code:

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

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.

Here's the whole piece of code:

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

And here's the whole error:

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)

回答1:


The documentation for getReferenceFromUrl(String fullUrl) states:

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

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

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

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"
  },


来源:https://stackoverflow.com/questions/40645018/firebase-bucketname-not-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!