【发布时间】:2021-04-28 07:21:58
【问题描述】:
我正在尝试创建一个“创建帖子”表单,用户可以在其中输入文本以及输入图像。
uploadImages() {
const files = document.querySelector('#imagesInput').files;
files.forEach(image => {
console.log("uploading", image.name)
const name = (+new Date()) + '-' + image.name;
const task = fb.storage.child(name).put(image, {contentType: image.type});
task.then(snapshot => {
snapshot.ref.getDownloadURL().then(url => {
console.log(url);
})
})
});
}
图片上传过程需要首先发生,我需要在数据库中创建帖子之前返回所有 URL(作为一个数组)。
imageURLs = this.uploadImages(); // <-- Wait for this to complete and return the image URIs
this.createPost("Hello, world!", imageURLs) // <-- then do this
【问题讨论】:
标签: javascript firebase-storage