I’m using this to try to get url into my real time database at firebase, but I only could store is time, path and content type, no url. The error is the 0 is undefined. Need help here, urgent. Thanks in advanced
This is my data.ts code.
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import firebase from 'firebase/app';
import { AngularFireStorage, AngularFireUploadTask } from 'angularfire2/storage';
import 'rxjs/Rx'
@Injectable()
export class DataProvider {
constructor(private db: AngularFireDatabase, private afStorage: AngularFireStorage) {
}
getFiles() {
let ref = this.db.list('files');
return ref.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
}
uploadToStorage(information): AngularFireUploadTask {
let newName = `${new Date().getTime()}.txt`;
return this.afStorage.ref(`files/${newName}`).putString(information);
}
storeInfoToDatabase(metainfo) {
let toSave = {
created: metainfo.timeCreated,
url: metainfo.downloadURL[0],
fullPath: metainfo.fullPath,
contentType: metainfo.contentType
}
return this.db.list('files').push(toSave);
}
deleteFile(file) {
let key = file.key;
let storagePath = file.fullPath;
let ref = this.db.list('files');
ref.remove(key);
return this.afStorage.ref(storagePath).delete();
}
}