0

I'm developing a simple Android application that downloads a file from Firebase storage.

Is there any way to download a file getting only a link to the file? I found a few methods but they were requiring also the name of file

I don't know the name of downloading file, I need to download the file knowing only its URL.


Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Tərlan Əhəd
  • 179
  • 3
  • 10
  • Possible duplicate of [Download a file with Android, and showing the progress in a ProgressDialog](https://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog) – Northern Poet Sep 22 '17 at 08:21
  • please read firebase documents because you're answer is available is firebase docs – Salman500 Sep 22 '17 at 18:47
  • I don't know why people downvoted this, I still needed to search for this method and your question helped me. – Zulqurnain Jutt Dec 03 '18 at 07:03

1 Answers1

1

Just try this :

FirebaseStorage storage = FirebaseStorage.getInstance();

StorageReference httpsReference = storage.getReferenceFromUrl("YOUR_FIREBASE_STORAGE_URL");

File localFile = File.createTempFile("PREFIX_FILE", "SUFFIX_FILE");

httpsReference.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
        // Local temp file has been created
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle any errors
    }
});

Firebase Storage documentation.

Pipiks
  • 2,018
  • 12
  • 27