.net 6的几种附件接收
1..net 6 附件上传
完整代码
[ApiController] [Route("[controller]")] public class UploadController : ControllerBase { /// <summary> /// 构造函数注入 /// </summary> private readonly ILogger<WeatherForecastController> _logger; public UploadController(ILogger<WeatherForecastController> logger) { _logger = logger; } /// <summary> /// 接收附件,第一种写法 /// </summary> /// <param name="files"></param> /// <returns></returns> [AllowAnonymous] [Route("/upload")] [HttpPost] public IActionResult Post(List<IFormFile> files) { var files1 = files; return Ok(); } /// <summary> /// 接收附件第二种写法 /// </summary> /// <param name="files"></param> /// <returns></returns> [AllowAnonymous] [Route("/upload1")] [HttpPost] public IActionResult Post(IFormCollection files) { var files1 = files; return Ok(); } /// <summary> /// 第三种写法 /// </summary> /// <param name="files"></param> /// <returns></returns> [AllowAnonymous] [Route("/upload2")] [HttpPost] public IActionResult Post(IFormFileCollection files) { var files1 = files; return Ok(); } }
.net版本
postman调用方式
2.serviceStack webapi上传附件以及接收,调用方式和上面相同
[Route("/Upload/Upload", $"Post", Summary = "上传", Notes = "上传")] public class Upload : IReturn<object> { public string? Name { get; set; } } public class UploadServices : Service { public ResultResponse<MessageMode> Post(Upload request) { var files = this.Request.Files; return ResultResponse<MessageMode>.Success(null); } }
过去的永远过去,未来的一直在等待.