Issues filed here should be about bugs in __the code in this repository__.
If you have a general question, need help debugging, or fall into some
other category use one of these other channels:
When trying to upload an object.
"Listing objects in a bucket is disallowed for rules_version = "1". Please update storage security rules to rules_verison = "2" to use list."
TODO(fredzqm): add more detailed steps.
Reference:
For more information, my upload code (in Kotlin) is
fun uploadImage(uri: Uri, path: String): Task<Uri> {
val storageRef = FirebaseStorage.getInstance().reference
val storagePath = storageRef.child(path)
return storagePath.putFile(uri).continueWithTask{ storageRef.downloadUrl }
}
I call it with
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode in 0..2 && resultCode == Activity.RESULT_OK) {
val cropImageUri = CropImage.getActivityResult(data).uri
val systemTime = System.currentTimeMillis()
val path = "$userId/$systemTime"
//IMAGE UPLOAD HERE:
FirebaseImageResource.uploadImage(cropImageUri, path)
.addOnCompleteListener {
if (it.isSuccessful) {
GlideApp.with(this)
.load(cropImageUri)
.into(imageViewForPosition(requestCode)!!)
imageUris[requestCode] = it.result.toString()
}
}
}
}
My firebase rules are the default:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
I'm also successfully authing with Facebook Login
override fun onSuccess(loginResult: LoginResult) {
val credential = FacebookAuthProvider.getCredential(loginResult.accessToken.token)
auth.signInWithCredential(credential)
}
(It lacks a success listener right now, but I know it's working because when I don't use it, I get an unauthorized error instead, and the file doesn't actually upload)
Android Studio Version: 3.4
All of my firebase dependencies are listed below
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.google.firebase:firebase-storage:17.0.0'
implementation 'com.firebaseui:firebase-ui-storage:4.3.2'
your trying to get URL from root reference
Just replace your downloadUrl code from
storageRef.downloadUrl
to
storagePath.downloadUrl
When a empty object path is used for get, it becomes a recursive list at the root of bucket, and generates a confusing error message.
For what it worth, I don't think there is a way for the error message to be better.
List example:
curl "https://firebasestorage.googleapis.com/v0/b/my-bucket/o?prefix=folder%2F&deimiter=/"
curl "https://firebasestorage.googleapis.com/v0/b/my-bucket/o/folder%2Ffile"
Hi! I also encountered the issue with similar code (but I used my reference instead of the path), but fixed it by modifying my rules and prepending rules_version = '2';
Like this:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
I believe this problem happens because a get request on the root of a bucket is indistinguishable from a list request.
I am adding a validation to getDownloadUrl.
Most helpful comment
Hi! I also encountered the issue with similar code (but I used my reference instead of the path), but fixed it by modifying my rules and prepending
rules_version = '2';Like this: