[英]How can I tell if it's an image or video - Firebase Storage/Firestore
I have several images on Firestore in an array.我在数组中的 Firestore 上有几张图片。 This array is in an object (house).
该数组位于 object(房子)中。 The array contains both images which are all in storage.
该数组包含两个图像,它们都在存储中。 I only saved the ULS each time.
我每次只保存 ULS。 How can I now check whether it is an image or a video from Firestore?
我现在如何检查它是来自 Firestore 的图像还是视频? When uploading I use a task Since I use the time when uploading to storage, I can't get the file name either.
上传时我用的是task 因为我用的是上传到存储时的时间,所以我也获取不到文件名。
Tasks.whenAllSuccess<UploadTask>(tasks).addOnSuccessListener {
val downloadUrls = mutableListOf<String>()
var count = 0
for(i in 0 until tasks.size){
tasks[i].result.metadata!!.reference!!.downloadUrl.addOnSuccessListener {uri->
downloadUrls.add(uri.toString())
count++
if(count == tasks.size)
{
progressDialog.dismiss()
saveInDatabase(downloadUrls)
}
}
}
}
private fun saveInDatabase(downloadUrls: MutableList<String>) {
var time = System.currentTimeMillis().toString()
val userHashMap = HashMap<String,Any>()
if(downloadUrls.isNotEmpty())
{
userHashMap["timestamp"] = time
userHashMap["type"] = mainType
userHashMap["img"] = mainImage
userHashMap["preis"] = 845
userHashMap["listImages"] = downloadUrls
}
if(latt != 0.0 && longt != 0.0)
{
userHashMap["long"] = longt
userHashMap["lat"] = latt
}
if(objektBeschreibung.text.toString().isNotEmpty())
{
userHashMap["beschreibung"] = objektBeschreibung.text.toString()
}
if(objektName.text.toString().isNotEmpty())
{
userHashMap["name"] = objektName.text.toString()
}
db.collection( "USER").document(auth.currentUser!!.uid).collection("Objekte").document(time).set(userHashMap, SetOptions.merge()).addOnSuccessListener {
Toast.makeText(ctx,"Erfolgreich angelegt",Toast.LENGTH_LONG).show()
}
}
As @DougStevenson already mentioned in his comment, Firestore doesn't know the type of files you have in the Storage.正如@DougStevenson 在他的评论中已经提到的那样,Firestore 不知道存储中的文件类型。 To know that, you have two solutions.
要知道这一点,您有两种解决方案。 The first one would be to search the download URL of the file for the extension and then process the file accordingly.
第一个是搜索文件的下载 URL 以查找扩展名,然后相应地处理文件。 Or, instead of storing the URLs in the database in an array, store them in a map:
或者,不是将 URL 存储在数据库中的数组中,而是将它们存储在 map 中:
$docId (documents)
|
--- urls (map)
|
--- "https://...": "audio"
|
--- "https://...": "video"
Where the key is the actual URL and the value is the type of the file.其中键是实际的 URL,值是文件的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.