Home > Java > javaTutorial > How to Get Download URLs from Firebase Storage After an Upload?

How to Get Download URLs from Firebase Storage After an Upload?

Barbara Streisand
Release: 2024-12-16 13:59:10
Original
937 people have browsed it

How to Get Download URLs from Firebase Storage After an Upload?

Obtaining Download URLs from Firebase Storage

Firebase Storage offers a convenient way to manage and share files in your Firebase project. Getting the download URL of an uploaded file is crucial for allowing users to access or share the file.

To retrieve the download URL from an upload task using Firebase Storage, avoid using taskSnapshot.getTask().getResult(). Instead, use the addOnSuccessListener method as demonstrated below:

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

                // Use the download URL as needed
            }
        });
    }
});
Copy after login

Note that as of Firebase Storage version 16.0.1, the deprecated methods StorageMetadata.getDownloadUrl() and UploadTask.TaskSnapshot.getDownloadUrl() have been removed.

Important Note:

It's essential to keep in mind that both the success and failure listeners will only be invoked once the data is committed to or rejected by the Firebase servers. Therefore, they may not be triggered if your device cannot establish a connection with the Firebase Storage backend.

The above is the detailed content of How to Get Download URLs from Firebase Storage After an Upload?. 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