无法将文件上传到我的Firebase存储 - 错误403禁止

时间:2017-06-06 11:16:57

标签: javascript firebase firebase-security firebase-storage

我尝试将文件(图片)上传到我的firebase存储空间中,并收到此错误:

  

POST https://firebasestorage.googleapis.com ... 403(禁止)

这是我的代码:

var storageRef = firebase.storage().ref('/images/' + file.name);
var uploadTask = storageRef.put(file);

// Register three observers:
// 1. 'state_changed' observer, called any time the state changes
// 2. Error observer, called on failure
// 3. Completion observer, called on successful completion
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
}, function(error) {
// Handle unsuccessful uploads
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
var downloadURL = uploadTask.snapshot.downloadURL;
});

我不知道代码是否与我的问题有关,但无论如何我都说了。 我想知道它是否是权限问题?

1 个答案:

答案 0 :(得分:0)

403()错误表示您无权上传到firebase存储,可能是因为默认权限规则需要您进行身份验证。要修复它,只需更改firebase控制台中的规则:)

例如,要授予未经授权的用户权限,请将中间行更改为:allow read, write: if true;