public IActionResult CreateImageRequest(FileImage imageFiles) { //net core access route to folder code string outPutFolder = @"C:\Users\LENOVO\source\repos\imageEditorProject\mvcImageEditor\wwwroot\uploads"; var backFileFinalPath = Path.Combine(outPutFolder, imageFiles.BackFileUpload.FileName); using (var fileStream = new FileStream(backFileFinalPath, FileMode.Create)) { imageFiles.BackFileUpload.CopyTo(fileStream); } var frontFileFinalPath = Path.Combine(outPutFolder, imageFiles.FrontFileUpload.FileName); using (var fileStream = new FileStream(frontFileFinalPath, FileMode.Create)) { imageFiles.FrontFileUpload.CopyTo(fileStream); } string newImagePath = ""; //string scriptPath = @"C:\Users\LENOVO\source\repos\imageEditorProject\TestLibrary\Scripts\transparenceFusionImageScript.py"; string tracePythonScript = ImageProcessingMethods.ExecuteTransparenceFusionScript(frontFileFinalPath, backFileFinalPath); //string tracePythonScript = @" hsrtwte e jertyejtkjrtuy C:\Users\LENOVO\source\repos\imageEditorProject\mvcImageEditor\wwwroot\uploads\created\aaa.png"; for (int x = tracePythonScript.Count(); x > 0; x--) { try { if (tracePythonScript.Substring(x, 2) == "C:") { int traceLenght = tracePythonScript.Count(); newImagePath = tracePythonScript.Substring(x, traceLenght - x - 2); break; } } catch (Exception) { } } //downloding the imagee+ Byte[] fileBytes = System.IO.File.ReadAllBytes(@newImagePath.Replace("\\", @"\")); return(File(fileBytes, "application/x-msdownload", newImagePath)); //return the same web downloading the image in browser }
public IActionResult CreateImageRequest(FileImage imageFiles) { //net core access route to folder code string outPutFolder = @".\uploads"; var backFileFinalPath = Path.Combine(outPutFolder, imageFiles.BackFileUpload.FileName); using (var fileStream = new FileStream(backFileFinalPath, FileMode.Create)) { imageFiles.BackFileUpload.CopyTo(fileStream); } var frontFileFinalPath = Path.Combine(outPutFolder, imageFiles.FrontFileUpload.FileName); using (var fileStream = new FileStream(frontFileFinalPath, FileMode.Create)) { imageFiles.FrontFileUpload.CopyTo(fileStream); } string newImagePath = ""; string tracePythonScript = ImageProcessingMethods.ExecuteTransparenceFusionScript(frontFileFinalPath, backFileFinalPath); for (int x = tracePythonScript.Count(); x > 0; x--) { try { if (tracePythonScript.Substring(x, 2) == "C:") { int traceLenght = tracePythonScript.Count(); newImagePath = tracePythonScript.Substring(x, traceLenght - x - 2); break; } } catch (Exception) { } } //downloding the imagee Byte[] fileBytes = System.IO.File.ReadAllBytes(@newImagePath.Replace("\\", @"\")); return(File(fileBytes, "application/x-msdownload", newImagePath)); }
/// <summary> /// Recieves the IFormFile and returns a receipt object from it which contains an OCR reading /// and a Regex analysis of key data points. /// </summary> private async Task <Receipt> CreateReceiptAsync(IFormFile image, string rootPath, double totalReceipts) { // Finds path to wwwroot string contentRootPath = _env.ContentRootPath; Receipt newReceipt = new Receipt(); newReceipt.Name = Path.GetFileName(image.FileName); // Creates a path to wwwroot\userReceipts for the image to be stored var ImagePath = @"userReceipts\"; var RelativeImagePath = ImagePath + newReceipt.Name; var AbsImagePath = Path.Combine(rootPath, RelativeImagePath); newReceipt.Path = AbsImagePath; // Stores the image file in wwwroot\userReceipts using (var fileStream = new FileStream(AbsImagePath, FileMode.Create)) { await image.CopyToAsync(fileStream); } // Fixes orientation on image ImageProcessingMethods.ImageOrient(AbsImagePath); // Runs an OCRReading on the image and returns a new Receipt // with the reading data var readReceipt = TesseractMethods.OCRRead(newReceipt, contentRootPath); if (!System.String.IsNullOrWhiteSpace(readReceipt.RawText)) { // Identifys the Vender readReceipt.Vendor = RegexMethods.IdentifyVendor(readReceipt.RawText, contentRootPath); // Finds the date and cost RegexMethods.FindDateAndCost(readReceipt, contentRootPath); } // Increments the receipts processed and stores the percentage of completion of all receipts in the // text file which can be read by the Status() method receiptsProcessed++; string percent = Convert.ToInt32((receiptsProcessed / totalReceipts) * 100).ToString(); // Catches possibility of exception being thrown because multiple asynchronous methods // may attempt to write or read from the file at the same time. try { if (totalReceipts - receiptsProcessed == 1) { System.IO.File.WriteAllText(Path.Combine(contentRootPath + "\\Log\\log.txt"), "100"); } else if (!(totalReceipts - receiptsProcessed == 0)) { System.IO.File.WriteAllText(Path.Combine(contentRootPath + "\\Log\\log.txt"), percent); } else { System.IO.File.WriteAllText(Path.Combine(contentRootPath + "\\Log\\log.txt"), "0"); } } catch (Exception e) { Trace.TraceError(e.ToString()); Debug.Write("Unexpected Error: " + e.Message); Debug.Write("Details: "); Debug.Write(e.ToString()); }; return(readReceipt); }