Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers;
[ParameterSwapControllerActionSelector(nameof(GetChildren), "id", typeof(int), typeof(Guid), typeof(Udi))]
public class MediaController : ContentControllerBase
{
private static readonly Semaphore _postAddFileSemaphore = new(1, 1);
private readonly AppCaches _appCaches;
private readonly IAuthorizationService _authorizationService;
private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor;
Expand Down Expand Up @@ -574,26 +575,30 @@ public async Task<IActionResult> PostSort(ContentSortOrder sorted)
public async Task<IActionResult> PostAddFile([FromForm] string path, [FromForm] string currentFolder,
[FromForm] string contentTypeAlias, List<IFormFile> file)
{
await _postAddFileSemaphore.WaitOneAsync();
var root = _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempFileUploads);
//ensure it exists
Directory.CreateDirectory(root);

//must have a file
if (file.Count == 0)
{
_postAddFileSemaphore.Release();
return NotFound();
}

//get the string json from the request
ActionResult<int?>? parentIdResult = await GetParentIdAsIntAsync(currentFolder, true);
if (!(parentIdResult?.Result is null))
{
_postAddFileSemaphore.Release();
return parentIdResult.Result;
}

var parentId = parentIdResult?.Value;
if (!parentId.HasValue)
{
_postAddFileSemaphore.Release();
return NotFound("The passed id doesn't exist");
}

Expand All @@ -605,6 +610,7 @@ public async Task<IActionResult> PostAddFile([FromForm] string path, [FromForm]
if (!IsFolderCreationAllowedHere(parentId.Value))
{
AddCancelMessage(tempFiles, _localizedTextService.Localize("speechBubbles", "folderUploadNotAllowed"));
_postAddFileSemaphore.Release();
return Ok(tempFiles);
}

Expand Down Expand Up @@ -638,6 +644,7 @@ public async Task<IActionResult> PostAddFile([FromForm] string path, [FromForm]
//if the media root is null, something went wrong, we'll abort
if (mediaRoot == null)
{
_postAddFileSemaphore.Release();
return Problem(
"The folder: " + folderName + " could not be used for storing images, its ID: " + parentId +
" returned null");
Expand Down Expand Up @@ -808,10 +815,12 @@ public async Task<IActionResult> PostAddFile([FromForm] string path, [FromForm]
KeyValuePair<string, StringValues> origin = HttpContext.Request.Query.First(x => x.Key == "origin");
if (origin.Value == "blueimp")
{
_postAddFileSemaphore.Release();
return new JsonResult(tempFiles); //Don't output the angular xsrf stuff, blue imp doesn't like that
}
}

_postAddFileSemaphore.Release();
return Ok(tempFiles);
}

Expand Down
Loading