首页 > 解决方案 > 在 Asp Core 中使用 IFormFile

问题描述

我用的是 asp core 2.2

    [HttpPost]
    [Route("Create")]
    public IActionResult Create([FromForm]SubjectWebFullDto newWeb)
    {
        try
        {
            if (!ModelState.IsValid)
                return BadRequest(new BadRequestError("Incorrect Model"));

            if (string.IsNullOrEmpty(newWeb.SourceWeb))
                return NotFound(new NotFoundError("Incorrect Model"));

            var subject = _subjectService.Get(newWeb.SubjectId);
            var newObj = newWeb.LoadFrom(subject.Guid);
            _subjectWebService.Insert(newObj);

            return Ok();
        }
        catch (System.Exception ex)
        {

        }
    }

在本地和服务器上没有上传图像的所有东西都很好。在本地响应上传图片时 OK: Local Api Post Man

但在服务器 iis 中失败: Server Api Post Man

我正在使用服务器 iis 7 在服务器中上传图像有什么问题?

模型:

public class SubjectWebFullDto
{

    public int WebId { get; set; }

    public string ImageUrl { get; set; }

    public IFormFile Image { get; set; }

    [MaxLength(200)]
    public string Name { get; set; }

    [MaxLength(10)]
    public string PublishDate { get; set; }

    [MaxLength(1000)]
    [Required]
    public string SourceWeb { get; set; }

    [MaxLength(300)]
    [Required]
    public string Lead { get; set; }

    public string Body { get; set; }

    [MaxLength(300)]
    public string Descript { get; set; }

    public int SubjectId { get; set; }
}

标签: asp.net-core

解决方案


推荐阅读