Home > Java > javaTutorial > How to Retrieve a Firebase Storage Download URL?

How to Retrieve a Firebase Storage Download URL?

Mary-Kate Olsen
Release: 2024-12-28 00:17:10
Original
144 people have browsed it

How to Retrieve a Firebase Storage Download URL?

Retrieving Download URL from Firebase:

In Firebase, getting the download URL for an uploaded file requires a different approach than using the getTask().getResult() method.

To obtain the download URL, you must utilize the addOnSuccessListener() method on the UploadTask. This method accepts a listener that handles the success scenario after a successful upload. Within the listener, invoke storageRef.getDownloadUrl().addOnSuccessListener() to retrieve the download URL as a Uri.

uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
        storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                String url = uri.toString();

                // Utilize the download URL for further operations
            }
        });
    }
});
Copy after login

The above is the detailed content of How to Retrieve a Firebase Storage Download URL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template