Firebase how to get Image Url from firebase storage?

后端 未结 12 724
悲&欢浪女
悲&欢浪女 2020-12-23 15:15

Right now i am fetching image from Storage of Firebase by using below code :

mStoreRef.child("photos/" + model.getBase64Image())
          .getDownl         


        
12条回答
  •  猫巷女王i
    2020-12-23 15:42

    The above method taskSnapshot.getMetadata().getDownloadUrl(); is deprecated and as a substitute provided this alternative:

    final StorageReference ref = storageRef.child("images/mountains.jpg");
    uploadTask = ref.putFile(file);
    
    Task urlTask = uploadTask.continueWithTask(new 
      Continuation>() {
         @Override
          public Task then(@NonNull Task task) throws Exception {
        if (!task.isSuccessful()) {
            throw task.getException();
        }
    
        // Continue with the task to get the download URL
        return ref.getDownloadUrl();
    }
    }).addOnCompleteListener(new OnCompleteListener() {
    @Override
    public void onComplete(@NonNull Task task) {
        if (task.isSuccessful()) {
            Uri downloadUri = task.getResult();
        } else {
            // Handle failures
            // ...
        }
      }
    });
    

提交回复
热议问题