This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -66,7 +67,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, $"Expected a multipart request, but got {Request.ContentType}"));
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, $"Expected a multipart request, but got {Request.ContentType}"));
|
||||||
|
|
||||||
//Save uploads to disk under temporary file names until we decide how to handle them
|
//Save uploads to disk under temporary file names until we decide how to handle them
|
||||||
uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
// uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);xx
|
||||||
|
|
||||||
|
|
||||||
string UploadObjectType = string.Empty;
|
string UploadObjectType = string.Empty;
|
||||||
@@ -75,6 +76,26 @@ namespace AyaNova.Api.Controllers
|
|||||||
string Notes = string.Empty;
|
string Notes = string.Empty;
|
||||||
List<UploadFileData> FileData = new List<UploadFileData>();
|
List<UploadFileData> FileData = new List<UploadFileData>();
|
||||||
|
|
||||||
|
//Save uploads to disk under temporary file names until we decide how to handle them
|
||||||
|
uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
||||||
|
if (!string.IsNullOrWhiteSpace(uploadFormData.Error))
|
||||||
|
{
|
||||||
|
errorMessage = uploadFormData.Error;
|
||||||
|
//delete temp files
|
||||||
|
ApiUploadProcessor.DeleteTempUploadFile(uploadFormData);
|
||||||
|
//file too large is most likely issue so in that case return this localized properly
|
||||||
|
if (errorMessage.Contains("413"))
|
||||||
|
{
|
||||||
|
var TransId = UserTranslationIdFromContext.Id(HttpContext.Items);
|
||||||
|
return BadRequest(new ApiErrorResponse(
|
||||||
|
ApiErrorCode.VALIDATION_LENGTH_EXCEEDED,
|
||||||
|
null,
|
||||||
|
String.Format(await TranslationBiz.GetTranslationStaticAsync("AyaFileFileTooLarge", TransId, ct), AyaNova.Util.FileUtil.GetBytesReadable(AyaNova.Util.ServerBootConfig.MAX_IMPORT_FILE_UPLOAD_BYTES))));
|
||||||
|
}
|
||||||
|
else//not too big, something else
|
||||||
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
if (!uploadFormData.FormFieldData.ContainsKey("FileData"))//only filedata is required
|
if (!uploadFormData.FormFieldData.ContainsKey("FileData"))//only filedata is required
|
||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Missing required FormFieldData value: FileData"));
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Missing required FormFieldData value: FileData"));
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
@@ -194,7 +195,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
ReportBiz biz = ReportBiz.GetBiz(ct, HttpContext);
|
ReportBiz biz = ReportBiz.GetBiz(ct, HttpContext);
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
|
|
||||||
var reportData = await biz.GetReportData(selectedRequest);
|
var reportData = await biz.GetReportData(selectedRequest);
|
||||||
if (reportData == null)
|
if (reportData == null)
|
||||||
@@ -321,7 +322,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpPost("upload")]
|
[HttpPost("upload")]
|
||||||
[DisableFormValueModelBinding]
|
[DisableFormValueModelBinding]
|
||||||
[RequestSizeLimit(15000000)]//currently the largest v7 export for a report template is 828kb, I'm guessing 15mb is more than enough
|
[RequestSizeLimit(AyaNova.Util.ServerBootConfig.MAX_REPORT_TEMPLATE_UPLOAD_BYTES)]
|
||||||
public async Task<IActionResult> UploadAsync()
|
public async Task<IActionResult> UploadAsync()
|
||||||
{
|
{
|
||||||
//Adapted from the example found here: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads#uploading-large-files-with-streaming
|
//Adapted from the example found here: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads#uploading-large-files-with-streaming
|
||||||
@@ -337,10 +338,28 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
|
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
|
||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, $"Expected a multipart request, but got {Request.ContentType}"));
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, $"Expected a multipart request, but got {Request.ContentType}"));
|
||||||
|
|
||||||
|
//Save uploads to disk under temporary file names until we decide how to handle them
|
||||||
|
// uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
||||||
|
|
||||||
//Save uploads to disk under temporary file names until we decide how to handle them
|
//Save uploads to disk under temporary file names until we decide how to handle them
|
||||||
uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
||||||
|
if (!string.IsNullOrWhiteSpace(uploadFormData.Error))
|
||||||
|
{
|
||||||
|
|
||||||
|
//delete temp files
|
||||||
|
ApiUploadProcessor.DeleteTempUploadFile(uploadFormData);
|
||||||
|
//file too large is most likely issue so in that case return this localized properly
|
||||||
|
if (uploadFormData.Error.Contains("413"))
|
||||||
|
{
|
||||||
|
var TransId = UserTranslationIdFromContext.Id(HttpContext.Items);
|
||||||
|
return BadRequest(new ApiErrorResponse(
|
||||||
|
ApiErrorCode.VALIDATION_LENGTH_EXCEEDED,
|
||||||
|
null,
|
||||||
|
String.Format(await TranslationBiz.GetTranslationStaticAsync("AyaFileFileTooLarge", TransId, ct), AyaNova.Util.FileUtil.GetBytesReadable(AyaNova.Util.ServerBootConfig.MAX_REPORT_TEMPLATE_UPLOAD_BYTES))));
|
||||||
|
}
|
||||||
|
else//not too big, something else
|
||||||
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, uploadFormData.Error));
|
||||||
|
}
|
||||||
|
|
||||||
List<UploadFileData> FileData = new List<UploadFileData>();
|
List<UploadFileData> FileData = new List<UploadFileData>();
|
||||||
|
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpPost("upload")]
|
[HttpPost("upload")]
|
||||||
[DisableFormValueModelBinding]
|
[DisableFormValueModelBinding]
|
||||||
[RequestSizeLimit(15000000)]//currently export file is 200kb * 50 maximum at a time = 15mb https://github.com/aspnet/Announcements/issues/267
|
[RequestSizeLimit(AyaNova.Util.ServerBootConfig.MAX_TRANSLATION_UPLOAD_BYTES)]
|
||||||
public async Task<IActionResult> UploadAsync()
|
public async Task<IActionResult> UploadAsync()
|
||||||
{
|
{
|
||||||
//Adapted from the example found here: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads#uploading-large-files-with-streaming
|
//Adapted from the example found here: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads#uploading-large-files-with-streaming
|
||||||
@@ -334,8 +334,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
|
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
|
||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, $"Expected a multipart request, but got {Request.ContentType}"));
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, $"Expected a multipart request, but got {Request.ContentType}"));
|
||||||
|
|
||||||
//Save uploads to disk under temporary file names until we decide how to handle them
|
|
||||||
uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
|
||||||
|
|
||||||
bool badRequest = false;
|
bool badRequest = false;
|
||||||
string UploadObjectType = string.Empty;
|
string UploadObjectType = string.Empty;
|
||||||
@@ -344,6 +342,27 @@ namespace AyaNova.Api.Controllers
|
|||||||
string Notes = string.Empty;
|
string Notes = string.Empty;
|
||||||
List<UploadFileData> FileData = new List<UploadFileData>();
|
List<UploadFileData> FileData = new List<UploadFileData>();
|
||||||
|
|
||||||
|
//Save uploads to disk under temporary file names until we decide how to handle them
|
||||||
|
uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
||||||
|
if (!string.IsNullOrWhiteSpace(uploadFormData.Error))
|
||||||
|
{
|
||||||
|
errorMessage = uploadFormData.Error;
|
||||||
|
//delete temp files
|
||||||
|
ApiUploadProcessor.DeleteTempUploadFile(uploadFormData);
|
||||||
|
//file too large is most likely issue so in that case return this localized properly
|
||||||
|
if (errorMessage.Contains("413"))
|
||||||
|
{
|
||||||
|
var TransId = UserTranslationIdFromContext.Id(HttpContext.Items);
|
||||||
|
return BadRequest(new ApiErrorResponse(
|
||||||
|
ApiErrorCode.VALIDATION_LENGTH_EXCEEDED,
|
||||||
|
null,
|
||||||
|
String.Format(await TranslationBiz.GetTranslationStaticAsync("AyaFileFileTooLarge", TransId, ct), AyaNova.Util.FileUtil.GetBytesReadable(AyaNova.Util.ServerBootConfig.MAX_TRANSLATION_UPLOAD_BYTES))));
|
||||||
|
}
|
||||||
|
else//not too big, something else
|
||||||
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!uploadFormData.FormFieldData.ContainsKey("FileData"))//only filedata is required
|
!uploadFormData.FormFieldData.ContainsKey("FileData"))//only filedata is required
|
||||||
{
|
{
|
||||||
@@ -469,7 +488,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Put (UpdateTranslationItemDisplayText)
|
/// Put (UpdateTranslationItemDisplayText)
|
||||||
/// Update a list of items with new display text
|
/// Update a list of items with new display text
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ namespace AyaNova.Util
|
|||||||
internal const int FAILED_AUTH_DELAY = 3000;//ms
|
internal const int FAILED_AUTH_DELAY = 3000;//ms
|
||||||
internal const int REPORT_RENDERING_OPERATION_TIMEOUT = 20000;//ms
|
internal const int REPORT_RENDERING_OPERATION_TIMEOUT = 20000;//ms
|
||||||
//UPLOAD LIMITS
|
//UPLOAD LIMITS
|
||||||
internal const long MAX_ATTACHMENT_UPLOAD_BYTES = 1048576;//10737418241=10gb in bytes, 1048576 = 1mb for testing
|
internal const long MAX_ATTACHMENT_UPLOAD_BYTES = 1048576;//10737418241=10GiB in bytes, 1048576 = 1MiB for testing
|
||||||
internal const long MAX_LOGO_UPLOAD_BYTES = 512000;//Max 500 KiB total (512000 bytes)
|
internal const long MAX_LOGO_UPLOAD_BYTES = 512000;//500KiB limit
|
||||||
internal const long MAX_IMPORT_FILE_UPLOAD_BYTES = 104857600;//100mib limit
|
internal const long MAX_IMPORT_FILE_UPLOAD_BYTES = 104857600;//100MiB limit
|
||||||
|
internal const long MAX_REPORT_TEMPLATE_UPLOAD_BYTES = 15728640;//15MiB limit; currently the largest v7 export for a report template is 828kb, I'm guessing 15mb is more than enough
|
||||||
|
internal const long MAX_TRANSLATION_UPLOAD_BYTES = 15728640;//15MiB limit; currently export file is 200kb * 50 maximum at a time = 15mb
|
||||||
//############################################################################################################
|
//############################################################################################################
|
||||||
|
|
||||||
//############################
|
//############################
|
||||||
|
|||||||
Reference in New Issue
Block a user