public async Task uploadImageHandler() { await _uploadHandler.Process(new UploadConfig() { AllowExtensions = _editorConfig.GetStringList("imageAllowFiles"), PathFormat = _editorConfig.GetString("imagePathFormat"), SizeLimit = _editorConfig.GetInt("imageMaxSize"), UploadFieldName = _editorConfig.GetString("imageFieldName"), ActionName = _editorConfig.GetString("imageActionName") }); }
public async Task Process(string pathToList, string[] searchExtensions) { this.SearchExtensions = searchExtensions.Select(x => x.ToLower()).ToArray(); this.PathToList = pathToList; try { Start = String.IsNullOrEmpty(_accessor.HttpContext.Request.Query["start"]) ? 0 : Convert.ToInt32(_accessor.HttpContext.Request.Query["start"]); Size = String.IsNullOrEmpty(_accessor.HttpContext.Request.Query["size"]) ? _editorConfig.GetInt("imageManagerListSize") : Convert.ToInt32(_accessor.HttpContext.Request.Query["size"]); } catch (FormatException) { State = ResultState.InvalidParam; await WriteResult(); return; } var buildingList = new List <String>(); try { //var localPath = Server.MapPath(PathToList); var localPath = Path.Combine(_hostingEnvironment.WebRootPath, PathToList); buildingList.AddRange(Directory.GetFiles(localPath, "*", SearchOption.AllDirectories) .Where(x => SearchExtensions.Contains(Path.GetExtension(x).ToLower())) .Select(x => PathToList + x.Substring(localPath.Length).Replace("\\", "/"))); Total = buildingList.Count; FileList = buildingList.OrderBy(x => x).Skip(Start).Take(Size).ToArray(); } catch (UnauthorizedAccessException) { State = ResultState.AuthorizError; } catch (DirectoryNotFoundException) { State = ResultState.PathNotFound; } catch (IOException) { State = ResultState.IOError; } finally { await WriteResult(); } }