【发布时间】:2020-02-07 09:12:31
【问题描述】:
我在尝试将个人资料照片更新到 Firebase 数据库时出错。
User.dashboard.html = User.editprofile.html
用户仪表盘.html
<input type="file" accept="image/*" name="file" id="file"
class="uploadPhoto" (change)="uploadPhotoURL($event)">
用户仪表盘.ts
import { AngularFireStorage, AngularFireUploadTask} from '@angular/fire/storage';
task: AngularFireUploadTask;
constructor(
private auth: AuthService,
private userService: UserService,
private storage: AngularFireStorage,
) { }
uploadPhotoURL(event): void {
const file = event.target.files[0];
const path = `users/${this.user.uid}/photos/${file.name}`;
if (file.type.split('/')[0] !== 'image') {
return alert('only images allowed'); // When this is not an image!
} else {
this.task = this.storage.upload(path, file);
// add this ref
const ref = this.storage.ref(path);
// and change the observable here
ref.getDownloadURL().subscribe(url => {
this.userService.updateProfileData(this.user.displayName, url);
});
}
}
在插入 img 文件后,该文件应该会自动上传到我的数据库中。
但是我遇到了这个错误:
错误错误:Firebase 选项中未定义存储桶。 @user.dashboard.html @<input type="file" accept="image/*" name="file" id="file" class="uploadPhoto" (change)="uploadPhotoURL($event)">
【问题讨论】:
-
请编辑问题以准确说明您如何将 Firebase 集成到您的应用中。似乎缺少配置。
标签: angular firebase firebase-storage angularfire2 angularfire