After upload a file in Android Firebase Storage how get the file download Url? getDownloadUrl() not working

前端 未结 6 1792
無奈伤痛
無奈伤痛 2020-12-01 14:21

In my new android firebase project, I used com.google.firebase:firebase-storage:16.0.1 library.

I get the following Error:

I opened ano

6条回答
  •  时光取名叫无心
    2020-12-01 15:01

    Firebase upadated their method so kindly update yourself use this method kindly:

    this is the basic line at which you feeling annoying, very simple justget the download path in this way

     StorageReference ref = storageReference.child("images/"+ UUID.randomUUID().toString());
      UploadTask  uploadTask = ref.putFile(filePath);
      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();
    
    
        ///here is your image url enjoy this 
    
              Toast.makeText(CloudStorageActivity.this, "Uploaded", Toast.LENGTH_SHORT).show();
    
            }
    
    
          } else {
    
    
            // Handle failures
            // ...
          }
        }
      });
    

提交回复
热议问题