ionic Angular 9 等待文件下载 url 可用
ionic Angular 9 wait until file download url is available
我正在使用 ionic 5 和 angular 9 将数据 url 上传到 firebase 存储。我的代码运行良好,但我不确定如何等到下载 url 可用。
下面是代码
uploadToFireStore(imageData){
const storage = getStorage();
const storageRef = ref(storage, (new Date().getTime().toString()));
uploadString(storageRef, imageData, 'data_url').then((snapshot) => {
getDownloadURL(snapshot.ref).then((downloadURL) => {
console.log('File available at', downloadURL);
this.downloadURL = downloadURL
});
});
}
我在我的相机插件中这样调用它
this.uploadToFireStore(base64Image)
console.log("updated with url:", this.downloadURL)
目前下载 url 稍后打印,我的代码不等待下载 url 到那里。我需要这个 url 上传到我的 RTDB 所以请告诉我如何在不将代码移到这部分的情况下做到这一点
getDownloadURL(snapshot.ref).then((downloadURL) => {
...
您可能只需要 return 您的承诺链:
uploadToFireStore(imageData){
const storage = getStorage();
const storageRef = ref(storage, (new Date().getTime().toString()));
return uploadString(storageRef, imageData, 'data_url').then((snapshot) => {
return getDownloadURL(snapshot.ref).then((downloadURL) => {
console.log('File available at', downloadURL);
this.downloadURL = downloadURL
});
});
}
那么你可以这样做:
this.uploadToFireStore(base64Image).then(() => {
console.log("updated with url:", this.downloadURL)
});
我正在使用 ionic 5 和 angular 9 将数据 url 上传到 firebase 存储。我的代码运行良好,但我不确定如何等到下载 url 可用。
下面是代码
uploadToFireStore(imageData){
const storage = getStorage();
const storageRef = ref(storage, (new Date().getTime().toString()));
uploadString(storageRef, imageData, 'data_url').then((snapshot) => {
getDownloadURL(snapshot.ref).then((downloadURL) => {
console.log('File available at', downloadURL);
this.downloadURL = downloadURL
});
});
}
我在我的相机插件中这样调用它
this.uploadToFireStore(base64Image)
console.log("updated with url:", this.downloadURL)
目前下载 url 稍后打印,我的代码不等待下载 url 到那里。我需要这个 url 上传到我的 RTDB 所以请告诉我如何在不将代码移到这部分的情况下做到这一点
getDownloadURL(snapshot.ref).then((downloadURL) => {
...
您可能只需要 return 您的承诺链:
uploadToFireStore(imageData){
const storage = getStorage();
const storageRef = ref(storage, (new Date().getTime().toString()));
return uploadString(storageRef, imageData, 'data_url').then((snapshot) => {
return getDownloadURL(snapshot.ref).then((downloadURL) => {
console.log('File available at', downloadURL);
this.downloadURL = downloadURL
});
});
}
那么你可以这样做:
this.uploadToFireStore(base64Image).then(() => {
console.log("updated with url:", this.downloadURL)
});