Angular 5 excel上传错误415不支持的媒体类型

时间:2018-06-16 03:43:11

标签: file-upload angular5

我正在尝试上传excel文件。我收到错误:415(不支持的媒体类型)

我已经按照这个样本。

how to pass excel file to C# controller from angular 4 in Visual Studio 2017?

组件

public uploadFile() {
        if (this.fileInput.files.length === 0) {
          return; // maybe needs more checking
        }

        const formData = new FormData();
        formData.append('file', this.fileInput.files[0]);
        this.component.customExcelUploadProvider.UploadExcelFile(formData, () => { }, () => { });
      }

服务:

 UploadExcelFile(ExcelFile: FormData, success: () => void, failure: () => void) {
    this.save(ExcelFile, success, failure);
  }

控制器:

  [HttpPost("CustomExcelFileUpload")]
        public IActionResult CustomExcelFileUpload([FromBody] IFormFile excelFile)
        {
            return Ok();
        }

0 个答案:

没有答案