public string GetUploadedFileSaveDir() { FileUploadConfig uploadConfig = this.dataLoader.GetUploadConfig(); string excelDir = uploadConfig.ExcelDir; return(excelDir); }
public (FileUploadConfig, string, string) GenerateConvertDirs(string datastoreName, string savedFileName, string scenario) { FileUploadConfig uploadConfig = this.dataLoader.GetUploadConfig(); PersistanceType persistanceType = this.dataLoader.GetPersistanceType(); FilePathConfig filePathConfig = this.dataLoader.GetFilePathConfig(); string excelDir = uploadConfig.ExcelDir; string pythonArgs = "--configPath \"" + uploadConfig.ColorConfigPath + "\" "; pythonArgs += " --srcPaths "; pythonArgs += "\"" + excelDir + Path.DirectorySeparatorChar + savedFileName + "\" "; pythonArgs += " --scenarios "; pythonArgs += "\"" + scenario + "\" "; string targetDir = null; if (persistanceType == PersistanceType.File && filePathConfig != null) { targetDir = filePathConfig.RootPath + Path.DirectorySeparatorChar + datastoreName; } else { targetDir = excelDir + Path.DirectorySeparatorChar + DateTime.Now.ToString("MMddyyyyHHmmss"); } pythonArgs += " --destPath \"" + targetDir + "\" "; return(uploadConfig, pythonArgs, targetDir); }
public string GetSavedExcelFilePath(string savedFileName) { FileUploadConfig uploadConfig = this.dataLoader.GetUploadConfig(); string excelDir = uploadConfig.ExcelDir; string savedExcelFilePath = excelDir + Path.DirectorySeparatorChar + savedFileName; return(savedExcelFilePath); }
private static void UseFileUploadConfig(IApplicationBuilder app, FileUploadConfig config) { if (!Directory.Exists(config.UploadPath)) { Directory.CreateDirectory(config.UploadPath); } app.UseStaticFiles(new StaticFileOptions() { RequestPath = config.RequestPath, FileProvider = new PhysicalFileProvider(config.UploadPath) }); }
/// <summary> /// 上传单文件 /// </summary> /// <param name="file"></param> /// <param name="config"></param> /// <param name="args"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <IResponseOutput <FileInfo> > UploadAsync(IFormFile file, FileUploadConfig config, object args, CancellationToken cancellationToken = default) { var res = new ResponseOutput <FileInfo>(); if (file == null || file.Length < 1) { return(res.NotOk("请上传文件!")); } //格式限制 if (!config.ContentType.Contains(file.ContentType)) { return(res.NotOk("文件格式错误")); } //大小限制 if (!(file.Length <= config.MaxSize)) { return(res.NotOk("文件过大")); } var fileInfo = new FileInfo(file.FileName, file.Length) { UploadPath = config.UploadPath, RequestPath = config.RequestPath }; var dateTimeFormat = config.DateTimeFormat.NotNull() ? DateTime.Now.ToString(config.DateTimeFormat) : ""; var format = config.Format.NotNull() ? StringHelper.Format(config.Format, args) : ""; fileInfo.RelativePath = Path.Combine(dateTimeFormat, format).ToPath(); if (!Directory.Exists(fileInfo.FileDirectory)) { Directory.CreateDirectory(fileInfo.FileDirectory); } fileInfo.SaveName = $"{IdWorkerHelper.GenId64()}.{fileInfo.Extension}"; await SaveAsync(file, fileInfo.FilePath, cancellationToken); return(res.Ok(fileInfo)); }
public ConfigurationServiceResponse SaveFile(Stream fileContent) { IFileUploadInfo fileUploadInfo = GetFileUploadInfo(fileContent); decimal maxFileSize = GetMaxFileSizeFromSysSettings(); var uploadSettings = new FileUploadConfig(fileUploadInfo) { SetCustomColumnsFromConfig = false, MaxFileSize = maxFileSize }; var response = new ConfigurationServiceResponse(); try { FileUploader.UploadFile(uploadSettings); } catch (MaxFileSizeExceededException ex) { response.Exception = ex; response.Success = false; } return(response); }
public DataLoader(IConfiguration config) { this.log = Log.Logger.ForContext <DataLoader>(); uploadConfig = config.GetSection("FileUploadConfig").Get <FileUploadConfig>(); persistanceType = (PersistanceType)Enum.Parse(typeof(PersistanceType), config.GetSection("PersistanceType").Value, true); if (persistanceType == PersistanceType.File) { this.filePathConfig = config.GetSection("FileDataPath").Get <FilePathConfig>(); this.dataAccessor = new FileDataAccessor(filePathConfig.RootPath); } else { string connectionString = config.GetConnectionString("MongoDbConnection"); string mgmtDBName = config.GetConnectionString("DataStoreMgmtDatabaseName"); this.dataAccessor = new MongoDataAccessor(connectionString, mgmtDBName); } }
public (string, string) GetTargetDirPath(string datastoreName) { FileUploadConfig uploadConfig = this.dataLoader.GetUploadConfig(); PersistanceType persistanceType = this.dataLoader.GetPersistanceType(); FilePathConfig filePathConfig = this.dataLoader.GetFilePathConfig(); string configPath = uploadConfig.ColorConfigPath; string targetDir = null; if (persistanceType == PersistanceType.File && filePathConfig != null) { targetDir = filePathConfig.RootPath + Path.DirectorySeparatorChar + datastoreName; } else { string excelDir = uploadConfig.ExcelDir; targetDir = excelDir + Path.DirectorySeparatorChar + DateTime.Now.ToString("MMddyyyyHHmmss"); } return(configPath, targetDir); }
public BaseResponse UploadReportTemplate(Stream fileContent) { HttpContext httpContext = HttpContextAccessor.GetInstance(); string reportId = httpContext.Request.QueryString["reportId"]; Guid report = new Guid(reportId); IFileUploadInfo fileUploadInfo = GetFileUploadInfo(fileContent); decimal maxFileSize = GetMaxFileSizeFromSysSettings(); var uploadSettings = new FileUploadConfig(fileUploadInfo) { SetCustomColumnsFromConfig = false, MaxFileSize = maxFileSize }; try { FileUploader.UploadFile(uploadSettings); if (IsLastChunk(uploadSettings.ByteRange)) { Stream template = ReportWorker.ValidateTemplate(uploadSettings.FileId); ReportWorker.SaveTemplate(template, report); SetResponseHttpStatus(HttpStatusCode.Created); } } catch (ArgumentException ex) { SetResponseHttpStatus(HttpStatusCode.InternalServerError); return(GetResponse(false, (int)HttpStatusCode.NotAcceptable)); } catch (ItemNotFoundException ex) { SetResponseHttpStatus(HttpStatusCode.InternalServerError); return(GetResponse(false, (int)HttpStatusCode.NotFound)); } catch (MaxFileSizeExceededException ex) { SetResponseHttpStatus(HttpStatusCode.LengthRequired); return(GetResponse(false, (int)HttpStatusCode.LengthRequired, ConvertBytesToMb(uploadSettings.MaxFileSize))); } catch (Exception ex) { SetResponseHttpStatus(HttpStatusCode.InternalServerError); return(GetResponse(false, (int)HttpStatusCode.MethodNotAllowed)); } return(GetResponse(true, null)); }
public UploadController(IOptions <AppSettings> config, ILogger <UploadController> logger, IUnitOfWork unitOfWork, IAuthorizationService authorizationService) { _config = config.Value.FileUploadConfig; _unitOfWork = unitOfWork; _authorizationService = authorizationService; }
public ProjectsController(IUnitOfWork unitOfWork, IOptions <AppSettings> config) { _unitOfWork = unitOfWork; _config = config.Value.FileUploadConfig; }
public FileService(IUnitOfWork unitOfWork, IOptions <AppSettings> config) { _unitOfWork = unitOfWork; _config = config.Value.FileUploadConfig; }
/// <summary> /// 上传单文件 /// </summary> /// <param name="file"></param> /// <param name="config"></param> /// <param name="args"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <IResponseEntity <FileInfo> > UploadFileAsync(IFormFile file, FileUploadConfig config, object args, CancellationToken cancellationToken = default) { var res = new ResponseEntity <FileInfo>(); if (file == null || file.Length < 1) { return(res.Error("请上传文件!")); } //格式限制 if (!config.ContentType.Contains(file.ContentType)) { return(res.Error("文件格式错误")); } //大小限制 if (!(file.Length <= config.MaxSize)) { return(res.Error("文件过大")); } var fileInfo = new File.FileInfo(file.FileName, file.Length) { UploadPath = config.UploadPath, RequestPath = config.RequestPath }; var dateTimeFormat = config.DateTimeFormat.IsNotNull() ? DateTime.Now.ToString(config.DateTimeFormat) : ""; var format = config.Format.IsNotNull() ? StringHelper.Format(config.Format, args) : ""; fileInfo.RelativePath = Path.Combine(dateTimeFormat, format).ToPath(); if (!Directory.Exists(fileInfo.FileDirectory)) { Directory.CreateDirectory(fileInfo.FileDirectory); } var dataCenterId = _systemConfig.CurrentValue?.DataCenterId ?? 5; var workId = _systemConfig.CurrentValue?.WorkId ?? 20; fileInfo.SaveName = $"{IdHelper.GenSnowflakeId(dataCenterId, workId)}.{fileInfo.Extension}"; await SaveAsync(file, fileInfo.FilePath, cancellationToken); return(res.Ok(fileInfo)); }