using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Net.Http.Headers;
using System;
using System.Threading.Tasks;
namespace Masuit.Tools.AspNetCore.ResumeFileResults.ResumeFileResult
{
///
/// 基于Stream的ResumeFileContentResult
///
public class ResumeFileContentResult : FileContentResult, IResumeFileResult
{
///
/// 构造函数
///
/// 文件二进制流
/// Content-Type
/// ETag
public ResumeFileContentResult(byte[] fileContents, string contentType, string etag = null) : this(fileContents, MediaTypeHeaderValue.Parse(contentType), !string.IsNullOrEmpty(etag) ? EntityTagHeaderValue.Parse(etag) : null)
{
}
///
/// 构造函数
///
/// 文件二进制流
/// Content-Type
/// ETag
public ResumeFileContentResult(byte[] fileContents, MediaTypeHeaderValue contentType, EntityTagHeaderValue etag = null) : base(fileContents, contentType)
{
EntityTag = etag;
EnableRangeProcessing = true;
}
///
public string FileInlineName { get; set; }
///
public override Task ExecuteResultAsync(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var executor = context.HttpContext.RequestServices.GetRequiredService>();
return executor.ExecuteAsync(context, this);
}
}
}