Angular Asp.net core角度上载错误:System.Text.DecoderFallbackException:无法转换索引处的字节[FF]

Angular Asp.net core角度上载错误:System.Text.DecoderFallbackException:无法转换索引处的字节[FF],angular,asp.net-core,Angular,Asp.net Core,我想上传一个包含Angular 7和Asp.net core 2.2的文件 在Angular web服务中附加文件并附加属性名 通过Angular调用WebSerice时,请在Asp.net核心日志中显示此错误。 我已经阅读了问题,并在内容类型中添加了utf-8,但再次显示错误。 我怎样才能解决它?内容类型的问题是否存在 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:Error: An unhandled ex

我想上传一个包含Angular 7和Asp.net core 2.2的文件
在Angular web服务中附加文件并附加属性名
通过Angular调用WebSerice时,请在Asp.net核心日志中显示此错误。
我已经阅读了问题,并在内容类型中添加了
utf-8
,但再次显示错误。
我怎样才能解决它?
内容类型的问题是否存在

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:Error: An unhandled exception has occurred while executing the request.

System.Text.DecoderFallbackException: Unable to translate bytes [FF] at index 144 from specified code page to Unicode.
   at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
   at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)
   at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes, Char*& chars)
   at System.Text.UTF8Encoding.FallbackInvalidByteSequence(Byte*& pSrc, Int32 ch, DecoderFallbackBuffer fallback, Char*& pTarget)
Asp.net核心:

[HttpPost("[action]")]
[AllowAnonymous]
public async Task<ReturnFromSpDto> AddFileInsertAsync(Test1 name)
{ .. }     
角度Html:

<input #file type="file" multiple (change)="upload(file.files)" />

将文件附加到formData时,请使用:

formData.append('file', file, file.name);
您正在使用文件名作为表单字段名,这可能会导致问题,
第二。不要将
内容类型设置为
应用程序/json
,让它保持
x-www-form-urlencoded

,尝试直接删除标题,并使用下面的代码发送post请求

upload(files) {
  if (files.length === 0)
  return;
  const formData: FormData = new FormData();
  formData.append('name', 'ads');
  formData.append('file', files[0], files[0].name);
  this.httpClient.post( `${this.appConfig.apiEndpoint}/api/doc/AddFileInsertAsync`, formData).subscribe(result => {
    console.log(result);
  }, error => console.error(error));
}
型号:

public class Test1
{
    public string Name { get; set; }
    public IFormFile File { get; set; }      
}
行动:

[HttpPost("[action]")]
[AllowAnonymous]
public async Task<ReturnFromSpDto> AddFileInsertAsync([FromForm]Test1 test)
{ .. } 
[HttpPost(“[action]”)
[异名]
公共异步任务AddFileInsertAsync([FromForm]Test1测试)
{ .. } 
public class Test1
{
    public string Name { get; set; }
    public IFormFile File { get; set; }      
}
[HttpPost("[action]")]
[AllowAnonymous]
public async Task<ReturnFromSpDto> AddFileInsertAsync([FromForm]Test1 test)
{ .. }