【问题标题】:what is the better way of upload image in angular project?在角度项目中上传图像的更好方法是什么?
【发布时间】:2020-02-01 11:50:02
【问题描述】:

我有一个网络摄像头,所以我需要捕获一张身份证并为我的 Angular 项目上传图像。任何人都建议我使用简单的 npm 库。

【问题讨论】:

标签: angular image file-upload npm-install


【解决方案1】:

使用formData上传方法如下:

 public upload(file: any): Observable<any> {

    let headers: HttpHeaders = new HttpHeaders();
    const params = new HttpParams();

    const formData: FormData = new FormData();
    if (file) {
      formData.append('file', file, file.name);
    }
    return this.http.put(this.Url, formData, { headers, params })
        .pipe(map((response: any) => {
          return response;
     }));
}

【讨论】:

    猜你喜欢
    • 2012-08-08
    • 2015-06-07
    • 1970-01-01
    • 2012-05-21
    • 1970-01-01
    • 2021-05-30
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多