How to receive a .txt file from the Firebase Storage and read it in android studio

0

Good afternoon, I had the question of how it is possible to get a text document from the firebase storage and read it in my android studio application. What happens that I have been looking for all day and I can not find any place where I explain how to get a text file from the storage of firebase and read it, if someone can clarify the doubt would be very helpful. Thank you very much in advance.

    
asked by Diego Lafaye A 12.12.2017 в 20:05
source

1 answer

1

It is not very complicated, first you create a path where the file is stored in firebase

StorageReference pathReference = storageRef.child("images/stars.jpg");

Then you create a FilePath inside the device where the file will be saved

File localFile = File.createTempFile("images", "jpg");

Finally you get the file with getFile()

pathReference.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
        // Local temp file has been created

           //Aqui ya obtuviste el archivo, asi que puedes chequear su tamaño con
     un log   

    Log.e("Tamaño del archivo",""+datasnapshot.getByteCount(); //creo que era byte count pero con un get byte obtenias el tamaño del archivo
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle any errors
    }
});

Then if you want you can put localFile.getAbsolutePath() and get where you have saved the txt file

I hope you serve, everything I wrote you got from the official documentation of firebase, where you can find how to save in memory, and other storage options, I recommend you read the documentation here

    
answered by 31.12.2017 в 17:15