简体   繁体   English

Angular / Firebase 上传文件错误:“[object Object]”

[英]Angular / Firebase upload file Error: "[object Object]"

EDIT : I found the solution needed to put the file name in the ref :编辑:我找到了将文件名放入 ref 所需的解决方案:

this.fireStorage.storage.ref(file.name).put(file);

I am trying to upload a file to FireStorage.我正在尝试将文件上传到 FireStorage。 But I am stuck on this error:但我坚持这个错误:

ERROR Error: "[object Object]" Angular 13 GedInputComponent.html:6:2 View_GedInputComponent_0 GedInputComponent.html:6 Angular 13错误错误:“[object Object]”Angular 13 GedInputComponent.html:6:2 View_GedInputComponent_0 GedInputComponent.html:6 Angular 13

ERROR CONTEXT Object { view: {…}, nodeIndex: 8, nodeDef: {…}, elDef: {…}, elView: {…} } GedInputComponent.html:6:2 View_GedInputComponent_0 GedInputComponent.html:6 Angular 13错误上下文对象 { view: {…}, nodeIndex: 8, nodeDef: {…}, elDef: {…}, elView: {…} } GedInputComponent.html:6:2 View_GedInputComponent_0 GedInputComponent.html:6 Angular 13

Here is my code :这是我的代码

<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>

Here I get the file :在这里我得到文件:

export class GedInputComponent {
  selectedFile: File;

  addFile() {
    this.gedService.uploadFile(this.selectedFile);
    this.dialogRef.close();
  }
  detectFile(event) {
    this.selectedFile = event.target.file;
  }
}

Here I try to upload the 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
  }
}

I think that you should do:我认为你应该这样做:

  detectFile(event) {
    this.selectedFile = event.target.files[0];
  }

Have a look at Uploading files with upload and at Using files from web applications .查看通过上传上传文件使用来自 Web 应用程序的文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM