taskSnapshot.getDownloadUrl() method not working

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


        
相关标签:
23条回答
  • 2020-12-08 08:46
    //firebase database
    implementation 'com.google.firebase:firebase-database:15.0.0'
    //firebase storage
    implementation 'com.google.firebase:firebase-storage:15.0.0'
    

    .getDownloadUrl() method is removed from later versions , i have changed it to 15.0.0 and works perfectly fine.You can find these in build.gradle(module:app)

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

    This will Solve Your Problem....

    if(uploadTask.isSuccessfull()){
    Task<Uri> uriTask=uploadTask.getResult().getStorage().getDownloadUrl();                                               while(!uriTask.isSuccessful());
    Uri downloadUri=uriTask.getResult();
    final String download_url=downloadUri.toString();
    }
    
    0 讨论(0)
  • 2020-12-08 08:49

    This will work:

    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
    
    
                    Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                    result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                            String photoStringLink = uri.toString();
                            Log.i("urlimage", photoStringLink);
                        }
                    });
                }
            });
    
    0 讨论(0)
  • 2020-12-08 08:49

    Try this:

    Uri download_uri ;
    
    final Map<String, String> userData = new HashMap<>();
        if (task != null) {
           //download_uri = task.getResult().getDownloadUrl();
          download_uri = task.getResult().getUploadSessionUri();
        }
        else {
            download_uri= imageUri;
        }
    
    userData.put("Image", download_uri.toString());
    userData.put("name",username);
    userData.put("category",category);
    userData.put("status",status);
    
    0 讨论(0)
  • 2020-12-08 08:50

    Edit: see this comment on why the approach in this answer doesn't work:

    firebaser here This answer is wrong. While it at first may appear to work (since it compiles) the result of getDownloadUrl().toString() is not a download URL, but a string representation of a Task object. For a better answer, see stackoverflow.com/a/55503926 or the sample in the Firebase documentation.

    Original answer below...


    In Firebase Storage API version 16.0.1, the getDownloadUrl() method using taskSnapshot object has changed. now you can use,

    taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
    

    to get download url from the firebase storage.

    0 讨论(0)
  • 2020-12-08 08:51
     ref.putFile(filePath)
                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
    
                            taskSnapshot.getStorage().getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
                                @Override
                                public void onComplete(@NonNull Task<Uri> task) {
                                    changeProfilePic(String.valueOf(task.getResult()));//gives image or file string url
                                }
                            });
    

    try this code will work for sure

    0 讨论(0)
提交回复
热议问题