![](/img/trans.png)
[英]How to get image URL from Firebase Storage in Android using Java?
[英]How can I get full URL (like below) from direct Firebase Storage for Android JAVA OR Kotlin
我想得到这个完整的 URL:
我想使用完整的 URL 在 android slider 中显示图像。
我得到了这个 URL gs://myapppakage-f7aa6.appspot.com/flat 44/image_1.jpg
但我无法访问要在我的 slider 中显示的图像。
我的 Kotlin 代码
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()
}
}
检查此链接: 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}")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.