我试图将文件上传到我的存储桶参考,但我收到了错误:
r
code
:
"storage/unauthorized"
message
:
"Firebase Storage: User does not have permission to access 'pdf'."
name
:
"FirebaseError"
serverResponse
:
"{↵ "error": {↵ "code": 403,↵ "message": "Permission denied. Could not perform this operation"↵ }↵}"
__proto__
:
Error
以下是我用来提交上传的代码:
submitUpload: function(){
var files = this.$refs.upload.uploadFiles;
console.log(files);
var storageRef = storage.ref();
var file = files[0]['raw'];
console.log(file + ' is the file');
var fileref = storageRef.child('pdf');
fileref.put(file).then(function(snapshot){
console.log('uploaded');
});
},
我使用element-ui上传组件来获取文件:
<el-upload drag class="upload-demo" ref="upload" :auto-upload="false" v-show="addItem.subcategory!=''">
<el-button slot="trigger" size="small" type="primary" style="margin-bottom: 10px;">select file</el-button>
<el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">upload to server</el-button>
<div class="el-upload__tip" slot="tip">PDFs no larger than 20 mb</div>
</el-upload>
以下是我的存储规则:
service firebase.storage {
match /{bucket}/o {
match /{allPaths=**} {
allow read, write
}
}
}
大多数有过类似问题的人都能够通过将规则改为现有规则来解决问题。关于可能导致这种情况的任何想法?
答案 0 :(得分:1)
事实证明{bucket}变量是问题所在。当我用我的应用程序的路径替换它时,它看起来像:
/b/xyz-app.appspot.com/o
我能够上传文件。
不确定把手是如何进入的 - 我不记得添加它们了。