This commit is contained in:
@@ -46,14 +46,14 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Upload Translation export file
|
/// Upload and import file
|
||||||
/// Max 15mb total
|
/// Max 100mb total
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Accepted</returns>
|
/// <returns>Accepted</returns>
|
||||||
[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(100000000)]//100mb limit https://github.com/aspnet/Announcements/issues/267
|
||||||
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
|
||||||
@@ -74,7 +74,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
bool badRequest = false;
|
bool badRequest = false;
|
||||||
string UploadObjectType = string.Empty;
|
string UploadObjectType = string.Empty;
|
||||||
string UploadObjectId = string.Empty;
|
|
||||||
string errorMessage = string.Empty;
|
string errorMessage = string.Empty;
|
||||||
string Notes = string.Empty;
|
string Notes = string.Empty;
|
||||||
List<UploadFileData> FileData = new List<UploadFileData>();
|
List<UploadFileData> FileData = new List<UploadFileData>();
|
||||||
@@ -89,20 +89,17 @@ namespace AyaNova.Api.Controllers
|
|||||||
{
|
{
|
||||||
if (uploadFormData.FormFieldData.ContainsKey("ObjectType"))
|
if (uploadFormData.FormFieldData.ContainsKey("ObjectType"))
|
||||||
UploadObjectType = uploadFormData.FormFieldData["ObjectType"].ToString();
|
UploadObjectType = uploadFormData.FormFieldData["ObjectType"].ToString();
|
||||||
if (uploadFormData.FormFieldData.ContainsKey("ObjectId"))
|
|
||||||
UploadObjectId = uploadFormData.FormFieldData["ObjectId"].ToString();
|
|
||||||
if (uploadFormData.FormFieldData.ContainsKey("Notes"))
|
|
||||||
Notes = uploadFormData.FormFieldData["Notes"].ToString();
|
|
||||||
//fileData in JSON stringify format which contains the actual last modified dates etc
|
//fileData in JSON stringify format which contains the actual last modified dates etc
|
||||||
//"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]"
|
//"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]"
|
||||||
FileData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UploadFileData>>(uploadFormData.FormFieldData["FileData"].ToString());
|
FileData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UploadFileData>>(uploadFormData.FormFieldData["FileData"].ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// long UserId = UserIdFromContext.Id(HttpContext.Items);
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
AyaType TheType = System.Enum.Parse<AyaType>(UploadObjectType, true);
|
||||||
|
log.LogDebug($"Instantiating biz object handler for {TheType}");
|
||||||
|
var biz = BizObjectFactory.GetBizObject(TheType, ct);
|
||||||
|
|
||||||
|
|
||||||
//We have our files now can parse and insert into db
|
//We have our files now can parse and insert into db
|
||||||
@@ -111,13 +108,8 @@ namespace AyaNova.Api.Controllers
|
|||||||
//deserialize each file and import
|
//deserialize each file and import
|
||||||
foreach (UploadedFileInfo a in uploadFormData.UploadedFiles)
|
foreach (UploadedFileInfo a in uploadFormData.UploadedFiles)
|
||||||
{
|
{
|
||||||
JObject o = JObject.Parse(System.IO.File.ReadAllText(a.InitialUploadedPathName));
|
JArray ja = JArray.Parse(System.IO.File.ReadAllText(a.InitialUploadedPathName));
|
||||||
if (!await biz.ImportAsync(o))
|
await ((IImportAbleObject)biz).ImportData(ja);
|
||||||
{
|
|
||||||
//delete all the files temporarily uploaded and return bad request
|
|
||||||
ApiUploadProcessor.DeleteTempUploadFile(uploadFormData);
|
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,21 +124,11 @@ namespace AyaNova.Api.Controllers
|
|||||||
ApiUploadProcessor.DeleteTempUploadFile(uploadFormData);
|
ApiUploadProcessor.DeleteTempUploadFile(uploadFormData);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Return the list of attachment ids and filenames
|
//TODO: Return results of operation here
|
||||||
return Accepted();
|
return Accepted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// private static void DeleteTempUploadFile(ApiUploadProcessor.ApiUploadedFilesResult uploadFormData)
|
|
||||||
// {
|
|
||||||
// if (uploadFormData.UploadedFiles.Count > 0)
|
|
||||||
// {
|
|
||||||
// foreach (UploadedFileInfo a in uploadFormData.UploadedFiles)
|
|
||||||
// {
|
|
||||||
// System.IO.File.Delete(a.InitialUploadedPathName);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user