node.js - 在Angular 9中进行post调用以将文件传递给express-fileupload的正确方法是什么?
问题描述
但在 Angular 中不起作用,这是 Angular 代码 js:
<input type="file" #fileUpload id="fileUpload" name="file" multiple="multiple" accept=".csv" />
const formData = new FormData();
formData.append('file', file);
this.caricautentiService.caricautenti(this.globals.idPersona,formData).subscribe( response => {
console.log(response);
});
这是服务:
if (file !== undefined) {
formParams = formParams.append('file', <any>file) as any || formParams;
}
return this.httpClient.request<any>('post',`${this.basePath}/caricautenti/${encodeURIComponent(String(idpersona))}`,
{
body: formParams,
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
我错过了什么?任何帮助表示赞赏,谢谢
解决方案
这对我有用:
public addFileToProgram(file: any): Observable<any> {
const formData = new FormData();
formData.append('file', file, file.name);
return this.http.post<any>('/v1/uploadfile', formData);
}
推荐阅读
- javascript - 解构为两个独立的变量
- powerbi - 所有页面的 PowerBI 日期过滤器
- python - 使用 vies.py 在 Django 中列出和详细视图错误
- google-analytics - 如何统一(在同一 ID 下)谷歌分析访问者数据和 CRM 客户数据
- performance - Powershell Invoke-Command 在一台计算机上连接速度非常慢
- c# - EF Core 查询自定义身份用户
- php - shell_exec 在虚拟机上工作,但不是通过 PHP
- go - 为什么 foo := foo() 不会导致错误?
- php - 通过 G-Suite 帐户上的 PHP API 访问 google 表格
- android - Android - 无法隐藏`TextInputLayout`/`TextInputEditText`下划线