我在使用 Firebase Storage 的 UploadTask 时遇到问题。我正在尝试上传图像,然后将图像 URL 保存在 Firestore Cloud 上。为此,我有以下代码:
newuploadImage() {
this.image = 'movie-' + new Date().getTime() + '.jpg';
let storageRef: any,
parseUpload: any;
storageRef = firebase.storage().ref('imgs/' + this.image);
parseUpload = storageRef.putString(this.cameraImage, 'data_url')
parseUpload.on('state_changed',
function (snapshot) {
}, function (error) {
}, function () {
// Upload completed successfully, now we can get the download URL
parseUpload.snapshot.ref.getDownloadURL().then(function (downloadURL) {
const idPubli = this.firestore.createId();
const idReto = this.firestore.createId();
let IDUser = firebase.auth().currentUser.uid;
let img = downloadURL
const idPuntPubli = this.firestore.createId();
let participacionCreadora = true;
let punt = 0;
this.firestore.doc(`public/${idPubli}`).set({
idPubli,
idReto,
IDUser,
img,
idPuntPubli,
participacionCreadora,
punt,
})
});
})
}
图像上传正常,但是当它尝试执行this.firestore时,控制台日志给了我这个错误:
错误类型错误:无法读取未定义的属性“firestore”
我不知道如何克服这个错误。
编辑
这是导入和构造函数,以防出现问题。
import { AngularFirestore} from 'angularfire2/firestore';
constructor(public camera: Camera, public firestore: AngularFirestore) {
}