简体   繁体   English

尽管允许读取和写入,但由于权限错误而将Firebase上传到存储桶失败

[英]Firebase Upload to Storage Bucket Failing due to Permission Error, despite Allowing Read + Write

I'm trying to upload files to my storage bucket ref, but I'm getting the error: 我正在尝试将文件上传到我的存储桶ref,但出现错误:

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

Here's the code I'm using to submit the upload: 这是我用来提交上传的代码:

 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');
     });
 },

I'm using an element-ui upload component to get the file: 我正在使用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>        

And here are my storage rules: 这是我的存储规则:

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

Most people who've had similar problems have been able to fix them by changing their rules to what I currently have. 大多数遇到过类似问题的人都可以通过将他们的规则更改为我当前的问题来解决它们。 Any ideas as to what could be causing this? 关于什么可能导致此的任何想法?

It turns out that the { bucket } variable was the problem. 事实证明,{bucket}变量是问题所在。 When I replaced it with the path of my app, which looks something like: 当我将其替换为应用程序的路径时,它类似于:

/b/xyz-app.appspot.com/o

I was able to upload documents. 我可以上传文件。

Not sure how the handlebars got in there -- I don't remember adding them. 不确定车把如何到达那里-我不记得添加它们了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular Error not allowing me to update and upload images in my Firebase Storage 找不到存储桶的原因 - Angular Error not allowing me to update and upload images in my Firebase Storage cause of not finding storage bucket React Native Image Upload的Firebase存储权限未知错误 - Firebase Storage Permission unknown error with React Native Image Upload Firebase 存储上传错误:无法读取未定义的属性“子” - Firebase Storage upload error: Cannot read property 'child' of undefined Firebase 存储错误:404 - ACCESS_BUCKET - Firebase Storage Error: 404 - ACCESS_BUCKET 无法上传到Firebase存储/权限被拒绝 - Can't upload to Firebase-Storage/Permission Denied 尝试将图像上传到 firebase 存储,但不断收到错误消息:无法读取未定义的属性“名称” - Trying to upload an image to firebase storage but keep getting the error: Cannot read property 'name' of undefined 尝试上载到存储时出现firebase错误 - Getting firebase error when trying to upload to storage 上传到firebase报错“.storage.ref不是函数” - Upload to firebase error ".storage.ref is not a function" 尝试将图像上传到 Firebase 存储时出错 - Error when trying to upload images to Firebase storage 未捕获的错误:Firebase 选项中未定义存储桶。 (网络) - Uncaught Error: No Storage Bucket defined in Firebase Options. (WEB)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM