0

I set up a firebase web project and cannot get the storage upload to work. I followed the instructions in firebase documentation.

My storage bucket permissions are public (and there's no difference if I change {bucket} to the actual name)

service firebase.storage {
    match /b/{bucket}/o {
        match /{allPaths=**} {
            allow read, write;
        }
    }
}

My code is

export function upload (fileName, file) {
  let ref = firebase.storage().ref()

  ref.child(fileName).putString(file, 'data_url').then(snapshot => {
    console.log('Uploaded file')
  }).catch(e => console.error(e))

And the error is

{
  "error": {
      "code": 400,
      "message": "Bad Request. Could not access bucket xx-xxx.appspot.com"
  }
}

I've tried to play around with the bucket permissions and I tried to add permissions in the google cloud storage as described here, which didn't help. Any ideas would be appreciated!

m-ke
  • 130
  • 2
  • 7

1 Answers1

0

Instead of using a wildcard for bucket, write it into your rule like:

service firebase.storage {
   match /b/xx-xxx.appspot.com/o {
       match /{allPaths=**} {
         allow read, write;
       }
   }
}

Edit:

For only public reading, try:

 service firebase.storage {
   match /b/xx-xxx.appspot.com/o {
     match /{allPaths=**} {
       allow read;
       allow write: if request.auth != null;
     }
   }
  } 
Rodrigo Mata
  • 1,779
  • 2
  • 14
  • 23