public async Task <IActionResult> UploadImage(IFormFile file, [FromForm] string name, [FromForm] string tags) { if (file == null) { file = Request.Form.Files[0]; } ImageOutput output = new ImageOutput(); if (file != null) { if (file.Length > 0) { //验证是否是图片 if (ImageValidation.IsCheck(file)) { ImageInput input = new ImageInput(); input.File = file; input.Name = name; input.Tags = tags; ImageHandleService handleService = new ImageHandleService(); //处理图片 output = await handleService.Processing(input, Request); return(Ok(output)); } } } return(BadRequest("图片上传失败!")); }
public async Task <IActionResult> UploadImages(List <IFormFile> files) { if (files.Count == 0) { if (Request.Form.Files.Count > 0) { foreach (var item in Request.Form.Files) { files.Add(item); } } } if (files.Count > 0) { List <ImageInput> imageInputs = new List <ImageInput>(); foreach (var file in files) { if (file.Length > 0) { //验证是否是图片 if (ImageValidation.IsCheck(file)) { ImageInput input = new ImageInput(); input.File = file; input.Name = file.Name; input.Tags = file.Name; imageInputs.Add(input); } } } ImageHandleService handleService = new ImageHandleService(); //处理图片 var output = await handleService.ProcessingImages(imageInputs, Request); return(Ok(output)); } return(BadRequest("图片上传失败!")); }