android - 如何在一个文档中存储多个图像(Firestore)Android
问题描述
用户应该能够在一篇文章中上传多张图片。我试图将所有 url 添加到 ArrayList,然后将它们存储到 firestore。我得到的只是错误。
“imageList”总是返回 null
这是我的代码:
fun uploadPost(images:ArrayList<Uri>, imageCount: Int, description:String){
images.forEach { image->
val imageRef = storageReferenence.child(System.currentTimeMillis().toString()
+"."+ image.lastPathSegment)
val uploadTask = imageRef.putFile((image))
uploadTask.addOnSuccessListener {
val downloadUrl = imageRef.downloadUrl
downloadUrl.addOnSuccessListener {uri->
Log.d("IMAGES", uri.toString())
imageList!!.add(uri.toString())
count++
}
}
}
//firebaseRepository.firestoreDB.collection("post").document(firebaseRepository.userid.toString()).update(post)
}
您可以看到 Log 具有 url,但是当我尝试将其添加到 imageList 时,它没有这样做。
这会导致错误:imageList!!.add(uri.toString()) 错误消息:AddViewModel$uploadPost$$inlined$forEach$lambda$1$1.onSuccess
我真的不知道将图像存储为数组或像这样存储每个图像更好: image1:url... , image2: url.. 我需要它们成为同一个文档的一部分。
解决方案
推荐阅读
- scala - 如何获取 Kafka 消费者(Alpakka)返回的 Map [String, String]?
- c# - 防止虚函数调用的泛型?
- apache-kafka - 是否可以仅使用消息(即使用 kafka)触发 oozie 工作流程
- sentiment-analysis - 情绪分析中的人工智能偏见
- r - R:用carrier::crate包装部分环境以预测新数据
- nginx - Nginx php-fpm“找不到文件”和可疑符号
- javascript - 如何指示 ESLint 忽略项目中的规则集?
- python - 尝试从字符串中删除 2 个子字符串
- json - 从 CLOB 数据类型列生成 Oracle JSON
- docker-compose - Docker:从“桥接网络容器”到主机网络容器的通信