angular - Firebase 无法以 Angular 的形式存储图像
问题描述
我想跨数组将图像存储到 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)
}
)
}
我Database
在 Firebase 中发送,但出现错误:
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;
}
}
解决方案
推荐阅读
- c++ - 将结构数据类型传递给 C++ 中的命名管道
- c# - . 主文件未在 asp.net iis 中呈现
- google-cloud-dataflow - 如何在谷歌云数据流中管理工人
- php - 如何更改 Joomla 表单值?
- excel - 将单元格转换为 BeforeClose VBA 中的一系列单元格
- yii2 - Yii2,如何在rest request中使用或操作符
- c# - Sphinx:sphinxQL 中的批量查询
- .htaccess - 如果 url 包含“.php”,则 htaccess 重定向到另一个页面
- node.js - 如何使 Localhost 节点 js Api 可公开访问
- android - runOnUiThread 如何在以下代码中工作而不影响现有的 UI 线程