using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.DependencyInjection; using System; using System.Threading.Tasks; namespace Microsoft.AspNetCore.Mvc { /// /// Represents an that when executed /// will write a file from a blob to the response. /// public class BlobStorageResult : FileResult { public BlobStorageResult(string blobUrl, string contentType) : base(contentType) { if (string.IsNullOrWhiteSpace(BlobUrl = blobUrl)) { throw new ArgumentException($"'{nameof(blobUrl)}' cannot be null or whitespace.", nameof(blobUrl)); } } /// Gets the URL for the block blob to be returned. public string BlobUrl { get; } /// Gets or sets the Content-Type header if the value is already known. public long? ContentLength { get; set; } /// /// Gets or sets whether blob properties should be retrieved before downloading. /// Useful when the file size is not known in advance /// public bool GetPropertiesBeforeDownload { 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); } } }