我有一个ASP.NET MVC 5应用程序。我的应用程序的关键功能之一是上传PDF文件并通过OCR读取一些值并做其他事情。
现在我想实现一个功能,使我的应用程序在特定时间检查特定文件夹(例如pdf_folder),检查是否有PDF文件,并自动上传每个PDF文件并执行我的应用程序的其余逻辑。在上传完所有文件后,它应将所有文件移动到另一个文件夹(finished_folder)。
例如,这是我的控制器,用于处理用户手动通过我的应用程序上传PDF时上传的文件。我只想使此过程在特定时间自动化。
原始回答:The feature you are looking for is called a scheduled task or a cron job. You can create a script that checks the specific folder for PDF files and then calls the controller action that handles file upload and OCR reading. This script can be executed at specific times using the built-in Windows Task Scheduler or a Linux cron job. After uploading, you can use another script to move the uploaded files to the finished_folder.
任何帮助都将不胜感激。
现在我想实现一个功能,使我的应用程序在特定时间检查特定文件夹(例如pdf_folder),检查是否有PDF文件,并自动上传每个PDF文件并执行我的应用程序的其余逻辑。在上传完所有文件后,它应将所有文件移动到另一个文件夹(finished_folder)。
例如,这是我的控制器,用于处理用户手动通过我的应用程序上传PDF时上传的文件。我只想使此过程在特定时间自动化。
原始回答:The feature you are looking for is called a scheduled task or a cron job. You can create a script that checks the specific folder for PDF files and then calls the controller action that handles file upload and OCR reading. This script can be executed at specific times using the built-in Windows Task Scheduler or a Linux cron job. After uploading, you can use another script to move the uploaded files to the finished_folder.
public ActionResult GetAlreadyScannedFileList(HttpPostedFileBase file)
{
string path = "";
if (file != null && file.ContentLength > 0)
{
UploadFileModel uploadFileModel = new UploadFileModel();
uploadFileModel.FileName = path;
uploadFileModel.UserId = 1;
//Unique guid should be generated for each and every uplaoded file.
Guid guid;
Session["Guid"] = guid = _uploadFileService.AddUploadFile(uploadFileModel);
//Save chnages.
_unitOfWork.Commit();
UploadFileModel uploadFile = _uploadFileService.GetUploadFileByGuid(guid);
int uploadFileId = uploadFile.UploadFileId;
_uploadFileService.ArchiveUploadFile(uploadFile.FileName);
//send complete mail
_uploadFileService.SendMailAfterComplete(uploadFileId);
return RedirectToAction("SplittedItems", "UploadFile", new { id = uploadFileId });
return RedirectToAction("GetAlreadyScannedFileList");
}
}
任何帮助都将不胜感激。
最初的回答。