首先,我想问一下没有时间离开这篇文章的人,因为这需要一些时间来阅读。其次,如果你还在这里,我会试着解释一下我自己无法处理的情况。
数据库:
Profile {
UID {
email
}
}
数据库:
Profile {
UID {
email
url
firstname
lastname
username
}
}
数据库:
Profile {
UID {
email
url
firstname
lastname
username
post* {
name (file name)
url (image url)
progress(upload progress)
}
}
}
我想做什么(努力尝试,但不能):
Profile {
UID {
email
url
firstname
lastname
username
post {
name (file name)
url (image url)
progress(upload progress)
inner { //new
description //new
title //new
url (post image 1) //new
url (post image 2) //new
url (post image 3) //new
}
}
}
代码: https://github.com/codediodeio/angular-firestarter
我正在使用此代码来实现此目的。我只需使用 上传服务 来创建新帖子。主要问题是我无法在upload.ts文件中添加任何其他字符串。
试过:
Upload.ts:
export class Upload {
$key: string;
file: File;
name: string;
title: string; //new
description: string; //new
url: string;
progress: number;
createdAt: Date = new Date();
constructor(file: File) {
this.file = file;
}
}
Upload.service.ts:
uploads: Observable<Upload[]>;
pushUpload(upload: Upload) {
const storageRef = firebase.storage().ref();
const uploadTask = storageRef.child(`${this.basePath}/${upload.file.name}`).put(upload.file);
uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
(snapshot: firebase.storage.UploadTaskSnapshot) => {
// upload in progress
const snap = snapshot;
upload.progress = (snap.bytesTransferred / snap.totalBytes) * 100
},
(error) => {
// upload failed
console.log(error);
},
() => {
// upload success
if (uploadTask.snapshot.downloadURL) {
upload.url = uploadTask.snapshot.downloadURL;
upload.name = upload.file.name;
this.saveFileData(upload);
return;
} else {
console.error('No download URL!');
}
},
);
}
upload.form.ts:
export class UploadFormComponent {
selectedFiles: FileList | null;
currentUpload: Upload;
uploads: Observable<Upload[]>
constructor(private upSvc: UploadService) { }
detectFiles($event: Event) {
this.selectedFiles = ($event.target as HTMLInputElement).files;
}
uploadSingle() {
const file = this.selectedFiles;
if (file && file.length === 1) {
this.currentUpload = new Upload(file.item(0));
this.upSvc.pushUpload(this.currentUpload);
} else {
console.error('No file found!');
}
}
}
upload.form.html:
<h3>Single File Upload</h3>
<label>
<input type="file" class="button" (change)="detectFiles($event)">
</label>
<input [(ngModel)]="uploads.title" type="text">
<input [(ngModel)]="uploads.description" type="text">
<button class="button is-primary" [disabled]="!selectedFiles" (click)="uploadSingle()">
</button>
错误(清除):
标题和说明未定义。
如果有人能解释我我在标题和描述上做错了什么会很好,并且可能会解释如何在这之后做出这两件事:
感谢您的时间。