Angular Firebase存储获取下载url并将阵列内部存储在Firestore中
我正在尝试将一组文件(图像)上载到Firebase存储,然后将它们的下载URL保存在Firestore的一个阵列中Angular Firebase存储获取下载url并将阵列内部存储在Firestore中,angular,typescript,firebase,google-cloud-firestore,google-cloud-storage,Angular,Typescript,Firebase,Google Cloud Firestore,Google Cloud Storage,我正在尝试将一组文件(图像)上载到Firebase存储,然后将它们的下载URL保存在Firestore的一个阵列中 uploadImages(name, images) { for (let i = 0; i < images.length; i++) { const file = images[i].file; const path = `${name}/${new Date().getTime()}_${file.name}`; this.t
uploadImages(name, images) {
for (let i = 0; i < images.length; i++) {
const file = images[i].file;
const path = `${name}/${new Date().getTime()}_${file.name}`;
this.task = this.storage.upload(path, file);
let snapshot = this.task.task.snapshot;
this.task.snapshotChanges().pipe(
finalize(() => {
snapshot.ref.getDownloadURL().then(downloadUrl => {
this.db.collection('test').doc()....
HOW DO I SAVE ALL DOWNLOAD URLS INSIDE OF AN ASCENDING ARRAY?
.then(() => {
console.log('Successfully uploaded image.');
})
.catch(error => {
throw new Error('Error uploading image:' + error);
});
});
})
).subscribe(snap => snapshot = snap);
}
}
上传图像(名称、图像){
for(设i=0;i{
snapshot.ref.getDownloadURL()。然后(downloadUrl=>{
此.db.collection('test').doc()。。。。
如何在升序数组中保存所有下载URL?
.然后(()=>{
log('已成功上载图像');
})
.catch(错误=>{
抛出新错误('上载图像时出错:'+错误);
});
});
})
).subscribe(snap=>snapshot=snap);
}
}
我的代码为每个图像提供下载url,但是如何将它们保存在一个升序数组中 您可以正常地将数组保存到Firestore数据库中,只需执行以下操作
this.db.collection([YOUR_COLLECTION]).add({link: [YOUR_ARRAY]});
其中[您的_数组]
包含您的下载URL。这样,您将创建一个Firestore文档,其中包含一个名为link
的字段,该字段是您的URL数组。此文档将具有自动生成的ID;如果要为文档提供一个id,则需要执行以下操作:
this.db.collection([YOUR_COLLECTION]).doc([YOUR_DOCUMENT]).set({link: arr});
就按升序排列该数组而言,在添加之前,您需要按照自己的意愿先对其进行组织。您可以正常地将数组保存到Firestore数据库中,只需执行以下操作
this.db.collection([YOUR_COLLECTION]).add({link: [YOUR_ARRAY]});
其中[您的_数组]
包含您的下载URL。这样,您将创建一个Firestore文档,其中包含一个名为link
的字段,该字段是您的URL数组。此文档将具有自动生成的ID;如果要为文档提供一个id,则需要执行以下操作:
this.db.collection([YOUR_COLLECTION]).doc([YOUR_DOCUMENT]).set({link: arr});
为了使该数组按升序排列,您需要在添加它之前按照您的意愿先对其进行组织