Firebase无法存储图像形式的Angular

时间:2018-11-02 08:56:48

标签: angular typescript firebase

我想将图像跨阵列存储到Firebase。 这是我的html:

 <input type="file" (change)="onFileSelected($event)">

    <button class="btn btn-primary" (click)="onUpload()">Clikc</button>

这是我的图片变量:selectedFile = null; 我在组件中的方法:

 onFileSelected(event) {

this.selectedFile = <File>event.target.files[0];
console.log(this.selectedFile);


}



onUpload() {
    const fb = new FormData();
    fb.append('image', this.selectedFile, this.selectedFile.name)
    this.http.post('https://ng-recipe-.firebaseio.com/', fb).subscribe(
      res => {
        console.log(res)
      }
    )
  }

我在Firebase中发送了Database,但出现错误:

POST https://ng-recipe-book-e.firebaseio.com/ 405 (Method Not Allowed)

有人知道如何在服务器上通过图像传递整个数组。

我要将此模型与服务器上的图像一起发送:

import { ProductModel } from "./product.model";

export class CategoryModel {

public name: string;
public description: string;
public image: FormData = null;
public products?: ProductModel[];
public file: File;

constructor(name: string, desciption: string, image: FormData = null, products: ProductModel[], file: File) {
    this.name = name;
    this.description = desciption;
    this.image = image;
    this.products = products;
    this.file = file;
}

}

0 个答案:

没有答案