在 angular 项目中上传图片的更好方法是什么?
what is the better way of upload image in angular project?
我有一个网络摄像头,所以我需要拍摄身份证并为我的 angular 项目上传图像。有人建议我使用简单的 npm 库来做这件事。
像下面的方法一样使用 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;
}));
}
我有一个网络摄像头,所以我需要拍摄身份证并为我的 angular 项目上传图像。有人建议我使用简单的 npm 库来做这件事。
像下面的方法一样使用 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;
}));
}