This commit is contained in:
2020-08-07 19:24:13 +00:00
parent c3eb8d95a2
commit b90236b81e

View File

@@ -17,7 +17,7 @@ using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Linq;
using System.Linq;
using AyaNova.Util;
using System.IO;
namespace AyaNova.Api.Controllers
@@ -127,7 +127,7 @@ namespace AyaNova.Api.Controllers
[HttpPost("{size}")]
[DisableFormValueModelBinding]
[RequestSizeLimit(15000000)]//currently export file is 200kb * 50 maximum at a time = 15mb https://github.com/aspnet/Announcements/issues/267
public async Task<IActionResult> UploadAsync([FromRoute] string size)
public async Task<IActionResult> UploadAsync([FromRoute] string size, IFormFile uploadFile)
{
//https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1#upload-small-files-with-buffered-model-binding-to-a-database
@@ -136,6 +136,32 @@ namespace AyaNova.Api.Controllers
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
using (var memoryStream = new MemoryStream())
{
await uploadFile.CopyToAsync(memoryStream);
// Upload the file if less than 2 MB
if (memoryStream.Length < 2097152)
{
var logo = new Logo()
{
Content = memoryStream.ToArray()
};
_dbContext.File.Add(file);
await _dbContext.SaveChangesAsync();
}
else
{
ModelState.AddModelError("File", "The file is too large.");
}
}
// AyaTypeId attachToObject = null;
ApiUploadProcessor.ApiUploadedFilesResult uploadFormData = null;
try