public async Task <IActionResult> DropFile() { var theFiles = HttpContext.Request.Form.Files; var uploadList = new List <UploadResult>(); string newFileName = string.Empty; var allowRootPath = false; var createThumbnail = false; var requestedFilePath = Request.Form["targetPath"].ToString(); //TODO: refactor, this is very cloudscribe core specific if (requestedFilePath == "/media/user-avatars") { var userName = User.Identity.Name; if (!string.IsNullOrWhiteSpace(userName)) { var safeSegment = _fileManagerService.GetSafeFolderSegment(userName); if (!string.IsNullOrWhiteSpace(safeSegment)) { requestedFilePath += "/" + safeSegment; } } } //_log.LogWarning($"requested upload path {requestedFilePath}"); bool?resizeImages = null; int? maxWidth = null; int? maxHeight = null; var smaxHeight = Request.Form["maxHeight"]; var smaxWidth = Request.Form["maxWidth"]; var sCreateThumbnail = Request.Form["createThumbnail"]; if (!string.IsNullOrWhiteSpace(smaxHeight) && !string.IsNullOrWhiteSpace(smaxWidth)) { try { maxWidth = Convert.ToInt32(smaxWidth); maxHeight = Convert.ToInt32(smaxHeight); resizeImages = true; } catch {} } var sResize = Request.Form["resizeImage"]; if (!string.IsNullOrWhiteSpace(sResize)) { var autoResize = true; bool.TryParse(sResize, out autoResize); if (!autoResize) { resizeImages = false; } } bool?keepOriginal = null; var sKeepOriginal = Request.Form["keepOriginal"]; if (!string.IsNullOrWhiteSpace(sKeepOriginal)) { // if passed this will override the default var tmpKeep = false; if (bool.TryParse(sKeepOriginal, out tmpKeep)) { keepOriginal = tmpKeep; } } if (!string.IsNullOrWhiteSpace(sCreateThumbnail)) { bool.TryParse(sCreateThumbnail, out createThumbnail); } var manageAuthResult = await _authorizationService.AuthorizeAsync(User, "FileManagerPolicy"); var lessPermissionAllowedExtensions = _autoUploadOptions.AllowedLessPrivilegedFileExtensions.Split('|').ToList(); foreach (var formFile in theFiles) { var ext = Path.GetExtension(formFile.FileName); var canSave = manageAuthResult.Succeeded || lessPermissionAllowedExtensions.Contains(ext); if (!canSave) { _log.LogWarning($"not allowing user {User.Identity.Name} to upload file {formFile.FileName} because the file extension is not allowed for less priviledged users"); continue; } try { if (formFile.Length > 0) { var uploadResult = await _fileManagerService.ProcessFile( formFile, _autoUploadOptions, resizeImages, maxWidth, maxHeight, requestedFilePath, newFileName, allowRootPath, createThumbnail, keepOriginal ).ConfigureAwait(false); uploadList.Add(uploadResult); } } catch (Exception ex) { _log.LogError(MediaLoggingEvents.FILE_PROCCESSING, ex, ex.StackTrace); } } foreach (var handler in _uploadHandlers) { try { await handler.Handle(uploadList); } catch (Exception ex) { _log.LogError($"{ex.Message}-{ex.StackTrace}"); } } return(Json(uploadList)); }