当我从Vue / NuxtJs发帖时,我收到的是null

问题描述 投票:0回答:1

当我尝试将图像从Vue / Nuxt发布到.net Core 2.1时,我得到null

可以检查我的代码有什么问题吗?

前端

async saveImage({
    commit
  }, files) {

    let signage = await this.$axios.$post(
      "http://localhost:56980/api/PlanImages/", {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }, files).then((response) => {
      alert(response.data);
    }).catch((error) => {
      console.log(error);
    });

  }
};

后端

    [HttpPost]
    public async Task<ActionResult> Post( IFormFile files)
    {
        var result = await UploadPhotosBucket.UploadPhoto(files);
        if (result.Success)
        {
            return Ok(new { result.FileName });
        }
        else
        {
            return BadRequest(_constants.RecordNotCreated());
        }
    }
.net axios nuxt
1个回答
0
投票

这个github回购可能对你有帮助ASP.NET Core FileUpload with Vue.JS & Axios

基本上,他使用IFormCollection文件而不是IList文件

© www.soinside.com 2019 - 2024. All rights reserved.