ResumeFileContentResult.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.AspNetCore.Mvc.Infrastructure;
  3. using Microsoft.Net.Http.Headers;
  4. namespace Masuit.Tools.AspNetCore.ResumeFileResults.ResumeFileResult;
  5. /// <summary>
  6. /// 基于Stream的ResumeFileContentResult
  7. /// </summary>
  8. public class ResumeFileContentResult : FileContentResult, IResumeFileResult
  9. {
  10. /// <summary>
  11. /// 构造函数
  12. /// </summary>
  13. /// <param name="fileContents">文件二进制流</param>
  14. /// <param name="contentType">Content-Type</param>
  15. /// <param name="etag">ETag</param>
  16. public ResumeFileContentResult(byte[] fileContents, string contentType, string etag = null) : this(fileContents, MediaTypeHeaderValue.Parse(contentType), !string.IsNullOrEmpty(etag) ? EntityTagHeaderValue.Parse(etag) : null)
  17. {
  18. }
  19. /// <summary>
  20. /// 构造函数
  21. /// </summary>
  22. /// <param name="fileContents">文件二进制流</param>
  23. /// <param name="contentType">Content-Type</param>
  24. /// <param name="etag">ETag</param>
  25. public ResumeFileContentResult(byte[] fileContents, MediaTypeHeaderValue contentType, EntityTagHeaderValue etag = null) : base(fileContents, contentType)
  26. {
  27. EntityTag = etag;
  28. EnableRangeProcessing = true;
  29. }
  30. /// <inheritdoc/>
  31. public string FileInlineName { get; set; }
  32. /// <inheritdoc/>
  33. public override Task ExecuteResultAsync(ActionContext context)
  34. {
  35. if (context == null)
  36. {
  37. throw new ArgumentNullException(nameof(context));
  38. }
  39. var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<ResumeFileContentResult>>();
  40. return executor.ExecuteAsync(context, this);
  41. }
  42. }