Android Question Firebase 3.2 crashes when uploading to storage

EstasPerplejo

Member
Licensed User
hi all.
In my game project I try uploading a file to the firebase storage bucket.
I can upload and delete files internally.

Initializing in the starter service_create as follows:
Storage.Initialize("Storage", "gs://hrm-2-56bb5.firebasestorage.app")

Bucket:
gs://hrm-2-56bb5.firebasestorage.app

Storage.Initialize(...) succeeds.

However:

Storage.UploadFile(...)

throws:

java.lang.IllegalArgumentException:
The supplied bucketname does not match the storage bucket of the current instance.

Stack trace:
FirebaseStorage.getReferenceFromUrl
FirebaseStorageWrapper.UploadFile

Looks like UploadFile() is not compatible with .firebasestorage.app buckets.

===================================================================
log:
-- UploadCloudBackup START ---
Uploading: settings.txt
Remote path: backups/settings.txt
b4xmainpage_uploadcloudbackup (java line: 3099)
java.lang.IllegalArgumentException: The supplied bucketname does not match the storage bucket of the current instance.
at com.google.android.gms.common.internal.Preconditions.checkArgument(com.google.android.gms:play-services-basement@@18.7.0:2)
at com.google.firebase.storage.FirebaseStorage.getReference(FirebaseStorage.java:347)
at com.google.firebase.storage.FirebaseStorage.getReferenceFromUrl(FirebaseStorage.java:312)
at anywheresoftware.b4x.objects.FirebaseStorageWrapper.UploadStream(FirebaseStorageWrapper.java:82)
at anywheresoftware.b4x.objects.FirebaseStorageWrapper.UploadFile(FirebaseStorageWrapper.java:75)
at de.dtm.hrm2.b4xmainpage._uploadcloudbackup(b4xmainpage.java:3099)
at de.dtm.hrm2.b4xmainpage$ResumableSub_btn_Instructions_Click.resume(b4xmainpage.java:791)
at de.dtm.hrm2.b4xmainpage._btn_instructions_click(b4xmainpage.java:771)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:8229)
at android.view.View.performClickInternal(View.java:8206)
at android.view.View.-$$Nest$mperformClickInternal(View.java:0)
at android.view.View$PerformClick.run(View.java:32007)
at android.os.Handler.handleCallback(Handler.java:1095)
at android.os.Handler.dispatchMessageImpl(Handler.java:135)
at android.os.Handler.dispatchMessage(Handler.java:125)
at android.os.Looper.loopOnce(Looper.java:269)
at android.os.Looper.loop(Looper.java:367)
at android.app.ActivityThread.main(ActivityThread.java:9333)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:566)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
*** Service (starter) Create ***
Storage.Initialize OK
Starter: StorageInitialized set to TRUE
Starter: OnStorageReady triggered
--- Starter Started: Connecting to Google Play ---
==========================================================================

Thanks for your help...

Using B4x 13.4 - Pages
FirebaseStorage Library: 3.2
 

EstasPerplejo

Member
Licensed User
Firebase is quite new to me and I am not really sure if I understand this correctly :

The upload path is: backups/settings.txt

Code:
Dim RemotePath As String = "backups/" & fileName
Starter.Storage.UploadFile(File.DirInternal, fileName, RemotePath)

Storage.Initialize succeeds.

The exception occurs inside UploadFile():
java.lang.IllegalArgumentException:
The supplied bucketname does not match the storage bucket of the current instance.

Do you mean a different upload path configuration than the RemotePath parameter?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need to define the rules in Firebase Console. For example, the test project rules are:
B4X:
rules_version = '2';
service firebase.storage {
  match /b/b4a-test1.appspot.com/o {
  match /auth/{allPaths=**} {
      allow read, write: if request.auth != null;
    }
    match /public/{allPaths=**} {
      allow read;
    }
    match /user/{userId}/{allPaths=**} {
      allow read, write: if request.auth.uid == userId;
    }

  }
}
 
Upvote 0

EstasPerplejo

Member
Licensed User
Thanks for the help and advice, I really appreciate this!
This has been a nightmare lasting for several weeks - i got it solved at last. However, not the way I thought...

Cause:
It had not been due to a programming error or a configuration issue, it was simply a Firebase project error - something must have gone completely wrong when creating this first project. It was not resolvable according to Google. I had to set up a complete new project, new rules, new google.service.json file and a new billing plan - Now the upload works as intended. There was absolutely nothing wrong with my code. I can't believe I had to spend nearly 6 weeks to resolve a technical error on the Google side!!!! This has been one of my most frustrating experiences with Google, and there were quite a few already!
Nonetheless, thanks for trying to help.
 
Upvote 0
Top