public static Result<StreamFileContent> File(StreamFileContent fileContent);
public static Result<ByteArrayFileContent> File(ByteArrayFileContent fileContent);
Usage
public class DownloadProformaInvoiceUseCase(
IHtmlTemplateLoader htmlTemplateLoader,
IHtmlConverter htmlConverter,
DownloadProformaInvoiceValidator validator)
{
public async Task<Result<ByteArrayFileContent>> DownloadAsPdfAsync(DownloadProformaInvoiceRequest request)
{
ValidationResult result = validator.Validate(request);
if (result.IsFailed())
return Result.Invalid(result.AsErrors());
var html = await htmlTemplateLoader
.LoadAsync("./Templates/ProformaInvoice.html", request.MapToObject());
byte[] fileContents = htmlConverter.ConvertToPdf(html, new MemoryStream());
var byteArrayFileContent = new ByteArrayFileContent(fileContents)
{
ContentType = "application/pdf",
FileName = "Report.pdf"
};
return Result.File(byteArrayFileContent);
}
}
If the result is successful, Result<ByteArrayFileContent> should be translated to an object like FileContentResult or FileStreamResult (these are types used in MVC controllers).
New types to be added:
These types represent the content of a file.
Two methods are added to the Result type:
Usage
If the result is successful,
Result<ByteArrayFileContent>
should be translated to an object like FileContentResult or FileStreamResult (these are types used in MVC controllers).Support should also be added for Minimal APIs. See, FileContentHttpResult and FileStreamHttpResult.