refactored upload so that it is not dependent on Folder Browse permission

This commit is contained in:
sbwalker 2023-07-10 11:44:05 -04:00
parent 2ccb814223
commit 16d0d11e0b
2 changed files with 27 additions and 21 deletions

View File

@ -329,26 +329,28 @@
var folder = (Folder == Constants.PackagesFolder) ? Folder : FolderId.ToString();
await interop.UploadFiles(posturl, folder, _guid, SiteState.AntiForgeryToken);
// uploading is asynchronous so we need to wait for the uploads to complete
// note that this will only wait a maximum of 15 seconds which may not be long enough for very large file uploads
bool success = false;
// uploading is asynchronous so we need to poll to determine if uploads are completed
var success = true;
int upload = 0;
while (upload < uploads.Length && success)
{
success = false;
// note that progressive retry will only wait a maximum of 15 seconds which may not be long enough for very large file uploads
int attempts = 0;
while (attempts < 5 && !success)
{
attempts += 1;
Thread.Sleep(1000 * attempts); // progressive retry
var file = await FileService.GetFileAsync(int.Parse(folder), uploads[upload]);
if (file != null)
{
success = true;
List<File> files = await FileService.GetFilesAsync(folder);
if (files.Count > 0)
{
foreach (string upload in uploads)
{
if (!files.Exists(item => item.Name == upload))
{
success = false;
}
}
if (success)
{
upload++;
}
}
@ -379,14 +381,14 @@
else
{
// set FileId to first file in upload collection
await GetFiles();
var file = _files.Where(item => item.Name == uploads[0]).FirstOrDefault();
var file = await FileService.GetFileAsync(int.Parse(folder), uploads[0]);
if (file != null)
{
FileId = file.FileId;
await SetImage();
await OnUpload.InvokeAsync(FileId);
}
await GetFiles();
StateHasChanged();
}
}

View File

@ -138,10 +138,14 @@ namespace Oqtane.Controllers
return file;
}
else
{
if (file != null)
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized File Get Attempt {Name} For Folder {FolderId}", name, folderId);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return null;
file = null;
}
return file;
}
}