How to get URL from Firebase Storage getDownloadURL

后端 未结 10 1986
小蘑菇
小蘑菇 2020-11-21 04:54

I\'m trying to get the \"long term persistent download link\" to files in our Firebase storage bucket. I\'ve changed the permissions of this to

service fireb         


        
10条回答
  •  我在风中等你
    2020-11-21 05:32

    here i am uploading and getting the image url at the same time...

               final StorageReference profileImageRef = FirebaseStorage.getInstance().getReference("profilepics/" + System.currentTimeMillis() + ".jpg");
    
                if (uriProfileImage != null) {
    
                profileImageRef.putFile(uriProfileImage)
                            .addOnSuccessListener(new OnSuccessListener() {
                                @Override
                                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                                   // profileImageUrl taskSnapshot.getDownloadUrl().toString(); //this is depreciated
    
                              //this is the new way to do it
                       profileImageRef.getDownloadUrl().addOnCompleteListener(new OnCompleteListener() {
                                        @Override
                                        public void onComplete(@NonNull Task task) {
                                           String profileImageUrl=task.getResult().toString();
                                            Log.i("URL",profileImageUrl);
                                        }
                                    });
                                }
                            })
                            .addOnFailureListener(new OnFailureListener() {
                                @Override
                                public void onFailure(@NonNull Exception e) {
                                    progressBar.setVisibility(View.GONE);
                                    Toast.makeText(ProfileActivity.this, "aaa "+e.getMessage(), Toast.LENGTH_SHORT).show();
                                }
                            });
                }
    

提交回复
热议问题