firebase storage is deleting my images when i try to download them

65 Views Asked by At

Whenever i run the following code firebase storage is deleting my image. My Log.d prints out the correct file location. I don't know why my images are being deleted instead of downloaded. `

    override fun getImage(url:String) = callbackFlow {
        val size: Long = 1024 * 1024 * 20 //20MB
        val storageRef = FirebaseStorage.getInstance().reference.child("images/${url}")
        Log.d("TEST", storageRef.toString())
        storageRef.getBytes(size).addOnSuccessListener {
            trySend(Response.Success(it))
        }.addOnFailureListener {
            trySend(Response.Failure(it))
        }
        awaitClose{
            storageRef.delete()
        }
    }

enter image description here

i tried different file extensions and just a few changes to code. I tried maximizing the byteArray.

1

There are 1 best solutions below

0
Frank van Puffelen On

You're calling:

storageRef.delete()

And StorageReference.delete() is documented to:

Deletes the object at this StorageReference.

So if you don't want to delete the image, don't call delete() on a reference to the image.