0

I have implemented the code below for downloading Firebase Storage file to memory. So, the next step is I want to access the file. How can I achieve that in this case?

 //Download to memory
    public void downloadToMemory(StorageReference sRefChild, String selectedFile)
{

    final long ONE_MEGABYTE = 1024 * 1024 *5;
    sRefChild.getBytes(ONE_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
        @Override
        public void onSuccess(byte[] bytes) {
            System.out.println("On success!");

        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle any errors
            System.out.println("Handle failure...");
        }
    });
bad_coder
  • 11,289
  • 20
  • 44
  • 72
sammy
  • 185
  • 2
  • 13
  • The data from Cloud Storage is available in `byte[] bytes`. You can do with it whatever you want there, including [writing it to a file](https://www.google.com/search?q=android+write+byte%5B%5D+to+file). But if you want to store it in a file, you might as well do that directly through the API, instead of first loading it into memory. See [downloading to a local file](https://firebase.google.com/docs/storage/android/download-files#download_to_a_local_file). – Frank van Puffelen Jan 26 '20 at 17:03
  • Ah okay, thanks a lot! I've used the approach of downloading to local file and I'm able to access the file now, thanks =D – sammy Jan 27 '20 at 17:51

1 Answers1

0

How do you want to access the file? By default you may use new ByteArrayOutputStream() as a storage. https://stackoverflow.com/a/17595282/6916890

lazylead
  • 1,453
  • 1
  • 14
  • 26