0

I am receiving the following error when uploading a file to Firebase storage from my web app.

{
  "error": {
    "code": 400,
    "message": "Permission denied. Could not access bucket firefileswebapp.appspot.com. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources."
  }
}

I was able to upload files previously without any error. This error is occurring suddenly without any change in my code. This is my code:

var newKey = 'key';
var fileRef = 'Files/' + user.uid + '/' + newKey + '/' + file.name;
var storage = firebase.storage().ref(fileRef);
var task = storage.put(file);
var fileSizeExceeded = false;
var fileSize = 0;

task.on('state_changed',function progress(snapshot){
    if(snapshot.totalBytes > 20971520){
        fileSizeExceeded = true;
        task.cancel();
    }

    fileSize = formatFileSize(snapshot.totalBytes);
    var percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
    var value = parseInt(percentage).toString() + '%';
    $('#file_label').css('background-size', value + ' 100%');
},

function error(err){
    loading('off');
    alert(err.message);
    this.uploadingFile = false;
    if(fileSizeExceeded) popUpBox('error','File size can not be larger than 20 mb',closeErrorPopUp,3000);
    else popUpBox('error','An error occured', closeErrorPopUp, 3000);
},

function complete(){
    // Do something
}

I have not changed storage rules in Firebase console. It is in its default state:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

what is the reason behind this error? How to solve this?

UPDATE: I found the solution in the accepted answer of this question

  • Is the user still signed in? log the `user.uid` to the console – James Poag May 14 '18 at 18:48
  • 1
    must be the same issue as this one. https://stackoverflow.com/questions/50292353/firebase-storage-security-rules-400-error-issue-permission-denied-could-not-ac/50298931#50298931 – goblin May 14 '18 at 18:53

0 Answers0