public async Task <IActionResult> Store(UploadForm form) { foreach (var file in form.files) { if (file.Length > 0) { var attachment = attachmentService.FindByName(file.FileName, form.postId); if (attachment == null) { throw new Exception(String.Format("attachmentService.FindByName({0},{1})", file.FileName, form.postId)); } var upload = await SaveFile(file); attachment.Type = upload.Type; attachment.Path = upload.Path; switch (upload.Type) { case ".jpg": case ".jpeg": case ".png": case ".gif": var image = Image.FromStream(file.OpenReadStream()); attachment.Width = image.Width; attachment.Height = image.Height; attachment.PreviewPath = upload.Path; break; case ".mp4": //截取影片預覽圖 string imgPath = Path.ChangeExtension(upload.Path, ".jpg"); string videoFullPath = Path.Combine(this.UploadFilesPath, upload.Path); string imgFullPath = Path.Combine(this.UploadFilesPath, imgPath); SaveVideoImage(videoFullPath, imgFullPath); attachment.PreviewPath = imgPath; break; } attachmentService.Update(attachment); } } return(new NoContentResult()); }