I'm uploading an image to Firebase Storage, I need the image URL in the Storage to use it then to insert it within a document in FireStore. How to get the url after the upload process is finished and not before it finished?
   public String uploadImage(byte[] bytes) {
        try {
            final StorageReference ref = storage.child("images/" + new Date().toString());
            ref.putBytes(bytes)
                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                            ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                                @Override
                                public void onSuccess(Uri uri) {
                                    res = uri.toString();
                                    return;
                                }
                            });
                        }
                    });
            System.out.println("RES : " + res);
            return res;
        }catch (NullPointerException e){
            return null;
        }
    }
//the variable res must return a not null value.