【发布时间】:2018-10-23 08:06:14
【问题描述】:
当我尝试将任何图像文件上传到 Firebase 存储时,我收到一条错误消息。
Object { code_: "storage/unauthorized", message_: "Firebase Storage: User does not have permission to access 'img/product/1540281542536/58916.jpg'.", serverResponse_: "{\n \"error\": {\n \"code\": 403,\n \"message\": \"Permission denied. Could not perform this operation\"\n }\n}", name_: "FirebaseError" }
不知道为什么不行
这是我的存储规则
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
match /img {
match /{allImages=**} {
allow read
}
match /product/{productID}/{imageId} {
allow create, write, delete: if request.auth != null
}
}
match /user/{userId} {
allow read, write: if request.auth.uid == userId;
}
}
}
}
这是我的上传代码
$formImgUpload.on('change', function (e) {
let file = this.files[0]
let rootRef = firebase.storage().ref()
let fileName = 'img/product/' + id + '/' + file.name
let fileRef = rootRef.child(fileName)
fileRef.put(file).then(function (result) {
console.log('"' + fileName + '" was uploaded successfully.')
result.ref.getDownloadURL().then(function (url) {
$img.attr('src', url)
$fileUrl.text(url)
})
}).catch(function (err) {
console.error(err)
})
})
谁能帮我写出正确的规则?
【问题讨论】: