Javascript 角度/火基上传文件错误:“0”;[对象对象]”;
编辑:我找到了将文件名放入ref中所需的解决方案:Javascript 角度/火基上传文件错误:“0”;[对象对象]”;,javascript,angular,firebase,firebase-storage,angularfire2,Javascript,Angular,Firebase,Firebase Storage,Angularfire2,编辑:我找到了将文件名放入ref中所需的解决方案: this.fireStorage.storage.ref(file.name).put(file); 我正在尝试将文件上载到FireStorage。 但我被这个错误所困扰: 错误:“[对象]” Angular 13 GedInputComponent.html:6:2 查看\u GedInputComponent\u 0 GedInputComponent.html:6 角度13 错误上下文对象{view:{…},nodeIndex:8,no
this.fireStorage.storage.ref(file.name).put(file);
我正在尝试将文件上载到FireStorage。
但我被这个错误所困扰:
错误:“[对象]”
Angular 13 GedInputComponent.html:6:2
查看\u GedInputComponent\u 0 GedInputComponent.html:6
角度13
错误上下文对象{view:{…},nodeIndex:8,nodeDef:{…},elDef:
{…},elView:{…}}GedInputComponent.html:6:2
查看\u GedInputComponent\u 0 GedInputComponent.html:6
角度13
这是我的代码:
<mat-dialog-content class="content">
<input type="file" (change)="detectFile($event)"/>
</mat-dialog-content>
<mat-dialog-actions class="buttons">
<button mat-raised-button (click)="addFile()">Add</button>
</mat-dialog-actions>
在这里,我尝试上载文件:
export class GedInputComponent {
selectedFile: File;
addFile() {
this.gedService.uploadFile(this.selectedFile);
this.dialogRef.close();
}
detectFile(event) {
this.selectedFile = event.target.file;
}
}
export class GedService {
constructor(private fireStorage: AngularFireStorage) { }
public uploadFile(file: File): void {
this.fireStorage.storage.ref().put(file); // When i remove this line there is no error
}
}
我认为你应该:
detectFile(event) {
this.selectedFile = event.target.files[0];
}
看看,看看 我认为您应该执行
this.selectedFile=event.target.file[0]代码>我已经试过了,但不起作用。不幸的是,我也犯了同样的错误。你看到@PierreDuc对我的答案所做的更正了吗?有个打字错误。谢谢你,皮尔雷克。