taskSnapshot.getDownloadUrl() method not working

后端 未结 23 757
有刺的猬
有刺的猬 2020-12-08 08:03
private void uploadImageToFirebaseStorage() {
    StorageReference profileImageRef =
        FirebaseStorage.getInstance().getReference(\"profilepics/\" + System.cur         


        
相关标签:
23条回答
  • 2020-12-08 08:51

    Try using this:

    taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
    
    0 讨论(0)
  • 2020-12-08 08:53

    FirebaseStorage Library version 19.0.1 works with

    String download_image_path = task.getResult().getUploadSessionUri().toString();
    
    0 讨论(0)
  • 2020-12-08 08:54

    You wont get the download url of image now using

    profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();
    

    this method is deprecated.

    Instead you can use the below method

        uniqueId = UUID.randomUUID().toString();
        ur_firebase_reference = storageReference.child("user_photos/" + uniqueId);
    
        Uri file = Uri.fromFile(new File(mphotofile.getAbsolutePath()));
        UploadTask uploadTask = ur_firebase_reference.putFile(file);
    
        Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
            @Override
            public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                if (!task.isSuccessful()) {
                    throw task.getException();
                }
    
                // Continue with the task to get the download URL
                return ur_firebase_reference.getDownloadUrl();
            }
        }).addOnCompleteListener(new OnCompleteListener<Uri>() {
            @Override
            public void onComplete(@NonNull Task<Uri> task) {
                if (task.isSuccessful()) {
                    Uri downloadUri = task.getResult();
                    System.out.println("Upload " + downloadUri);
                    Toast.makeText(mActivity, "Successfully uploaded", Toast.LENGTH_SHORT).show();
                    if (downloadUri != null) {
    
                        String photoStringLink = downloadUri.toString(); //YOU WILL GET THE DOWNLOAD URL HERE !!!!
                        System.out.println("Upload " + photoStringLink);
    
                    }
    
                } else {
                    // Handle failures
                    // ...
                }
            }
        });
    
    0 讨论(0)
  • 2020-12-08 08:55

    Only that...

    taskSnapshot.getStorage().getDownloadUrl();

    Task<Uri> result = taskSnapshot.getStorage().getDownloadUrl();
    result.addOnSuccessListener(new OnSuccessListener<Uri>() {
       @Override
       public void onSuccess(Uri uri) {
           String photoStringLink = uri.toString();
           mDatavaseRef.push().setValue(photoStringLink);
       }
    });
    
    0 讨论(0)
  • 2020-12-08 08:56

    To get imageUrl path from storage use this code:

    uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            if (taskSnapshot.getMetadata() != null) {
                if (taskSnapshot.getMetadata().getReference() != null) {
                    Task<Uri> result = taskSnapshot.getStorage().getDownloadUrl();
                    result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                            String imageUrl = uri.toString();
                            //createNewPost(imageUrl);
                        }
                    });
                }
            }
        }});
    

    that is all

    0 讨论(0)
  • 2020-12-08 08:56

    for latest version try

    profileImageUrl = taskSnapshot.getStorage().getDownloadUrl().toString();
    
    0 讨论(0)
提交回复
热议问题