我试图让我的用户一次上传多张图片.现在一切都正常工作了,我唯一的问题是我没有在firebase firestore文档中获得作为数组的下载URL.
我正在使用arrayUnion()函数将所有内容合并到一个数组中,但它给了我这个错误."Unhandled Rejection (ReferenceError): arrayUnion is not defined"
我做错了什么?
这是我的代码:
firebase
.firestore()
.collection("Properties")
.add({
propname: propName,
price: price,
bedrooms: bedroom,
bathroom: bathroom,
exclusive: exclusive,
area: area,
type: type,
category: category,
features: features,
services: services,
summary: summary,
// imageUrls: urls,
location: location,
salesAgentID: salesAgent,
date: getCurrentDate(),
})
.then(result => {
const promises = [];
Promise.all(
selectedImages.map(image => {
const storageRef = storage.ref(
`propertyImages/${result.id}/${image.name}`
);
storageRef.put(image).then(urls => {
storageRef.getDownloadURL().then(downloadUrls => {
console.log(downloadUrls);
firebase
.firestore()
.collection("Properties")
.doc(result.id)
.update({
propertyID: result.id,
images: arrayUnion(downloadUrls),//here is my problem
})
.then(res => {
//handleUploadChange();
alert("Property Added Successfully");
window.location.reload();
});
});
});
})
);
});