简体   繁体   中英

How can I get full URL (like below) from direct Firebase Storage for Android JAVA OR Kotlin

I want to get this full URL:

https://firebasestorage.googleapis.com/v0/b/myapppakage-f7aa6.appspot.com/o/flat%2044%2F1image_1.jpg?alt=media&token=8907b845-a1f5-4bdb-8e76-215fc6fc5129

I want to show images in android slider using full URL.

I got this URL gs://myapppakage-f7aa6.appspot.com/flat 44/image_1.jpg
But I can`t access images to show in my slider.

My Kotlin Code

private fun retriveImagesFromStorage(flatName: String) {

 val firebaseStorage = FirebaseStorage.getInstance().reference
 val storageRef: StorageReference = firebaseStorage.child(flatName)

 storageRef.listAll().addOnSuccessListener { result ->
            // go through all the files/folders
            imageList.clear()
            result.items.forEach { storageRef ->
                // get the download URL for each of the file
               storageRef.downloadUrl.addOnSuccessListener { uri ->
                   imageList.add(uri.path.toString())
               }
            }
        }
        .addOnFailureListener {
            Toast.makeText(this, "Unable to fetch items!", Toast.LENGTH_SHORT).show()
            it.printStackTrace()
        }

}

Check this link: https://firebase.google.com/docs/storage/android/download-files#download_data_via_url

val storageRef = Firebase.storage.reference
storageRef.child("folder/subfolder/picture.png").downloadUrl
    .addOnSuccessListener { url ->
        // do whatever with your url
    }
    .addOnFailureListener { exception ->
        Log.e(TAG, "Exception: ${exception.message}")
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM