如何修复“ Firebase存储:用户无权访问”错误,即使我知道它已登录

我对Angular和Firebase还是陌生的。当我使用以下方法将图像上传到Firebase存储时,这是我的问题。当我上载图像时,该图像甚至用户似乎都已登录,但是控制台说“ Firebase存储:用户无权访问对象”。我想知道我该怎么办?

我使用的代码是该库的最新Angular和Ionic。 在此之前,我曾尝试修改Firebase Storage中的规则,但是所有这些尝试均失败了

profile.page.ts:

type OptionalInfo = { 
    name?: string
    ...
}

我的安全规则:

export interface Image {
  id: string;
  image: string;
}

@Component({
  selector: 'app-profile',templateUrl: './profile.page.html',styleUrls: ['./profile.page.scss'],})

export class ProfilePage {

  public isPublic: boolean;

  validations_form: FormGroup;
  // matching_passwords_group: FormGroup;
  errorMessage: string = '';
  successMessage: string = '';



 url: any;
 newImage: Image = {
  id: this.afs.createId(),image: ''
 }
 loading: boolean = false;
 downloadURL: any;
  userEmail: string;
;


  uploadImage(event) {

    var user = firebase.auth().currentUser;


    console.log(user.email);

    this.loading = false;
    if (event.target.files && event.target.files[0]) {
      var reader = new FileReader();

      reader.readAsDataURL(event.target.files[0]);
      // For Preview Of Image
      reader.onload = (e:any) => { // called once readAsDataURL is completed
        this.url = e.target.result;

        // For Uploading Image To Firebase
        const fileraw = event.target.files[0];
        console.log(fileraw)


        const filePath = '/Style/' + user.uid + '/Image' + (Math.floor(1000 + Math.random() * 9000) + 1);
        const result = this.SaveImageRef(filePath,fileraw);
        const ref = result.ref;
        result.task.then(a => {
          ref.getDownloadURL().subscribe(a => {
            console.log(a);

            this.newImage.image = a;
            this.loading = false;

          });

          this.afs.collection("Style").doc(user.uid).set(this.newImage);

        });
      },error => {
        alert("Error");
      }

    }

  }



  SaveImageRef(filePath,file) {

    return {
      task: this.afStorage.upload(filePath,file),ref: this.afStorage.ref(filePath)
    };
  }

期望的是用户被授权并具有对Firebase存储的全部访问权限。

xiaotong11 回答:如何修复“ Firebase存储:用户无权访问”错误,即使我知道它已登录

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3157502.html

大家都在问