C# 如何将文件从Angular传输到C Web API
我需要从angular发布一个文件,代码如下:C# 如何将文件从Angular传输到C Web API,c#,angular,file,C#,Angular,File,我需要从angular发布一个文件,代码如下: addBudgetAttachment(budgetCode:string, file: File){ const url = environment.webServiceUrl + "Attachments?budgetId=" + budgetCode; return this.http.post<string>(url,file); } public string Post([FromBody] FileSt
addBudgetAttachment(budgetCode:string, file: File){
const url = environment.webServiceUrl + "Attachments?budgetId=" + budgetCode;
return this.http.post<string>(url,file);
}
public string Post([FromBody] FileStream file, string budgetId){
return budgetId;
}
在这个C方法中,将文件保存在一个目录中,我已经尝试了所有可能的方法,但是没有任何效果。您已经在C中实现了post方法,所以您必须像这样从http post方法体中发送数据
addBudgetAttachment(budgetCode:string, file: File){
const url = environment.webServiceUrl;
const formData = new FormData();
formData.append('file', file);
formData.append('budgetCode', budgetCode);
return this.http.post<string>(url,formData);
}