Files
Saxonite/SaxoniteCoreWeb/Base/Procs/Data/UploadFileData.cs
T
2024-02-27 15:45:47 +00:00

63 lines
2.1 KiB
C#

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
{
//=======================================================================
/// <summary>
/// Object to persist upload file after request has terminated, and the Form File has been disposed.
/// <para>- Too allow async processes to access the file after request completed.</para>
/// </summary>
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.
/// <summary>Gets the raw Content-Disposition header of the uploaded file.</summary>
public String ContentDisposition { get; }
/// <summary>Gets the raw Content-Type header of the uploaded file.</summary>
public String ContentType { get; }
/// <summary>Gets the file name from the Content-Disposition header.</summary>
public String FileName { get; }
/// <summary>Gets the header dictionary of the uploaded file.</summary>
public Dictionary<String, String> Headers { get; } = new Dictionary<String, String>();
/// <summary>Gets the file length in bytes.</summary>
public long Length { get; }
/// <summary>Gets the form field name from the Content-Disposition header.</summary>
public String Name { get; }
/// <summary>File data.</summary>
public byte[] FileData { get; }
//-------------------------------------------------------------------
}
//=======================================================================
}