How to check if a file exists in Firebase storage from your android application?

前端 未结 5 1793
忘掉有多难
忘掉有多难 2021-01-01 19:38

I am developing android application where a user clicks image, it gets stored in firebase, cloud functions process this image and stores the output back in the firebase in t

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 20:21

    This is how I am currently checking to see if the file Exists.

    The this.auth.user$ pulls an observable that displays the current user's data from the FireStore database. I store the FileStorage profile image reference in the FireStore database.

    I then use the File Path in the user's data and use it for the FileStorage reference.

    Now use the observable and check to see if the downloadURL length is less than or equal to 0.

    If it is indeed greater than zero then the file exists; then go do something. Else do something else.

    ngOnInit() {
        this.userSubscription = this.auth.user$.subscribe((x) => {
        console.log(x);
        this.userUID = x.userId;
        this.userPhotoRef = x.appPhotoRef;
        this.userDownloadURL = x.appPhotoURL;
        });
        const storageRef = this.storage.ref(this.userPhotoRef);
        console.log(storageRef);
        if (storageRef.getDownloadURL.length <= 0) {
          console.log('File Does not Exist');
        } else {
          console.log('File Exists');
        }
      }
    

提交回复
热议问题