using Microsoft.AspNetCore.Http; using Sarand.Net.Standard.Base.Core; using System; using System.Collections.Generic; using System.IO; using System.Text; namespace Saxonite.Net.Core.Web.Base.Procs.Data { //======================================================================= /// /// Object to persist upload file after request has terminated, and the Form File has been disposed. /// - Too allow async processes to access the file after request completed. /// public class UploadFileData { //------------------------------------------------------------------- public UploadFileData(IFormFile dataFile) { ContentDisposition = dataFile.ContentDisposition; ContentType = dataFile.ContentType; FileName = dataFile.FileName; Length = dataFile.Length; Name = dataFile.Name; foreach (var header in dataFile.Headers) Headers.Add(header.Key, header.Value.ToString()); // Load file data. using (MemoryStream stream = new MemoryStream()) { dataFile.CopyTo(stream); FileData = stream.ToArray(); } } //------------------------------------------------------------------- // Properties. /// Gets the raw Content-Disposition header of the uploaded file. public String ContentDisposition { get; } /// Gets the raw Content-Type header of the uploaded file. public String ContentType { get; } /// Gets the file name from the Content-Disposition header. public String FileName { get; } /// Gets the header dictionary of the uploaded file. public Dictionary Headers { get; } = new Dictionary(); /// Gets the file length in bytes. public long Length { get; } /// Gets the form field name from the Content-Disposition header. public String Name { get; } /// File data. public byte[] FileData { get; } //------------------------------------------------------------------- } //======================================================================= }