This commit is contained in:
@@ -23,36 +23,16 @@ namespace AyaNova.Api.ControllerHelpers
|
||||
internal static class ApiUploadProcessor
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Process uploaded attachment file
|
||||
/// Will be treated as a temporary file for further processing into database
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns></returns>
|
||||
internal static async Task<ApiUploadedFilesResult> ProcessAttachmentUploadAsync(Microsoft.AspNetCore.Http.HttpContext httpContext)
|
||||
{
|
||||
return await ProcessUploadAsync(httpContext, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Process uploaded utility file (backup)
|
||||
/// Anything that will be stored in the backup folder as is
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns></returns>
|
||||
internal static async Task<ApiUploadedFilesResult> ProcessUtilityFileUploadAsync(Microsoft.AspNetCore.Http.HttpContext httpContext)
|
||||
{
|
||||
return await ProcessUploadAsync(httpContext, false);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// handle upload
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <param name="processAsAttachment"></param>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns><see cref="ApiUploadedFilesResult"/> list of files and form field data (if present)</returns>
|
||||
private static async Task<ApiUploadedFilesResult> ProcessUploadAsync(Microsoft.AspNetCore.Http.HttpContext httpContext, bool processAsAttachment)
|
||||
internal static async Task<ApiUploadedFilesResult> ProcessUploadAsync(Microsoft.AspNetCore.Http.HttpContext httpContext)
|
||||
{
|
||||
|
||||
ApiUploadedFilesResult result = new ApiUploadedFilesResult();
|
||||
@@ -69,7 +49,6 @@ namespace AyaNova.Api.ControllerHelpers
|
||||
|
||||
var section = await reader.ReadNextSectionAsync();
|
||||
|
||||
|
||||
while (section != null)
|
||||
{
|
||||
ContentDispositionHeaderValue contentDisposition;
|
||||
@@ -83,24 +62,13 @@ namespace AyaNova.Api.ControllerHelpers
|
||||
string filePathAndName = string.Empty;
|
||||
var CleanedUploadFileName = contentDisposition.FileName.Value.Replace("\"", "");
|
||||
|
||||
if (processAsAttachment)
|
||||
{
|
||||
//get temp file path and temp file name
|
||||
filePathAndName = FileUtil.NewRandomAttachmentFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
//store directly into the backup file folder
|
||||
//NOTE: all utility files are always stored as lowercase to avoid recognition issues down the road
|
||||
CleanedUploadFileName = CleanedUploadFileName.ToLowerInvariant();
|
||||
filePathAndName = FileUtil.GetFullPathForUtilityFile(CleanedUploadFileName);
|
||||
}
|
||||
|
||||
//get temp file path and temp file name
|
||||
filePathAndName = FileUtil.NewRandomUserFilesFolderFileName;
|
||||
|
||||
//save to disk
|
||||
using (var stream = new FileStream(filePathAndName, FileMode.Create))
|
||||
{
|
||||
await section.Body.CopyToAsync(stream);
|
||||
await section.Body.CopyToAsync(stream);
|
||||
}
|
||||
result.UploadedFiles.Add(new UploadedFileInfo()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user