【问题标题】:Angular / Firebase upload file Error: "[object Object]"Angular / Firebase 上传文件错误:“[object Object]”
【发布时间】:2020-05-29 15:41:51
【问题描述】:

编辑:我找到了将文件名放入 ref 所需的解决方案:

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

我正在尝试将文件上传到 FireStorage。 但我被这个错误困住了:

错误错误:“[对象对象]” Angular 13 GedInputComponent.html:6:2 View_GedInputComponent_0 GedInputComponent.html:6 角 13

ERROR CONTEXT Object { view: {…}, nodeIndex: 8, nodeDef: {…}, elDef: {…}, elView: {…} } GedInputComponent.html:6:2 View_GedInputComponent_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
  }
}

【问题讨论】:

  • 我认为你应该这样做this.selectedFile = event.target.file[0];
  • 我已经尝试过了,但它不起作用。不幸的是我有同样的错误
  • 您看到@PierreDuc 对我的回答所做的更正了吗?有一个错字。谢谢皮埃尔杜克。

标签: javascript angular firebase firebase-storage angularfire2


【解决方案1】:

我认为你应该这样做:

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

查看Uploading files with uploadUsing files from web applications

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-03
    • 2018-09-30
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    相关资源
    最近更新 更多