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

How to Retrieve a Firebase Storage Download URL?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-28 00:17:10205browse

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
            }
        });
    }
});

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!

Statement:
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