【问题标题】:ERROR N code: "auth/internal-error" message: "Photo URL too long." Prototype N错误 N 代码:“auth/internal-error”消息:“照片 URL 太长。”原型 N
【发布时间】:2020-02-16 04:04:06
【问题描述】:

我正在尝试使用 cordova 相机插件更新 firebase 个人资料图片。但我有一个错误。请问有什么办法吗?

   async openLibrary() {
    const options: CameraOptions = {
    quality: 70,
    destinationType: this.camera.DestinationType.DATA_URL,
    sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
    encodingType: this.camera.EncodingType.JPEG,
    saveToPhotoAlbum: false
    };
   return await this.camera.getPicture(options);
  }


  async addPhoto() {
  const libraryImage = await this.openLibrary();
  this.photoCamera = 'data:image/jpeg;base64,' + libraryImage;
  }

   enregisterPseudoo() {

   this.user.updateProfile({
     displayName: this.pseudo,
     photoURL:(this.photoCamera)
     }).then(data => {
     this.navCtrl.push(TabsPage, {
       name: this.pseudo,
       photo:(this.photoCamera),
       });
     });
       }

网址太长了,请问有什么办法吗?

【问题讨论】:

  • 你能补充一下错误是什么吗?
  • @yazantahhan 这是错误:错误 N 代码:“auth/internal-error”消息:“照片 URL 太长。”原型N

标签: javascript firebase ionic-framework firebase-authentication


【解决方案1】:

Firebase 身份验证中用户个人资料中的photoURL 必须是指向现有图像的链接。您正在尝试将图像存储为 Firebase 身份验证无法处理的数据 URL。

因此,您必须将数据上传到图像托管服务(例如Cloud Storage for Firebase),然后将生成的 URL 保存到用户配置文件中。

【讨论】:

    【解决方案2】:

    这对我有用。将图像存储在 firebase 存储中,然后获取 url

       const libraryImage = await this.openLibrary();
       this.photoCamera = 'data:image/jpeg;base64,' + libraryImage;
         let user = firebase.auth().currentUser;
         this.avatarStgRef = firebase.storage().ref("pictures" + user.uid);
         this.avatarStgRef.putString(this.photoCamera, 'data_url'); 
    
        this.avatarStgRef.getDownloadURL().then(
        (url)=>{
       this.user.updateProfile({
       displayName: this.pseudo,
      photoURL: url
        }).then(data => {
        this.navCtrl.push(TabsPage, {
        name: this.pseudo,
        photo: url,
         });
          });
    

    })

    【讨论】:

    • 感谢您的回答。有用。就我而言,我必须这样做: firebase.storage().ref('pictures/'+user.uid+'/avatar.jpg');
    猜你喜欢
    • 2022-06-21
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2017-11-23
    • 2011-12-06
    • 2019-01-13
    • 2021-12-16
    相关资源
    最近更新 更多