diff --git a/Oqtane.Client/Modules/Controls/FileManager.razor b/Oqtane.Client/Modules/Controls/FileManager.razor
index 4bd49824..ea60ac22 100644
--- a/Oqtane.Client/Modules/Controls/FileManager.razor
+++ b/Oqtane.Client/Modules/Controls/FileManager.razor
@@ -61,6 +61,12 @@
{
}
+ @if (MaxUploadFileSize > 0)
+ {
+
+ @string.Format(Localizer["File.MaxSize"], MaxUploadFileSize)
+
+ }
@@ -163,6 +169,9 @@
[Parameter]
public int ChunkSize { get; set; } = 1; // optional - size of file chunks to upload in MB
+ [Parameter]
+ public int MaxUploadFileSize { get; set; } = -1; // optional - maximum upload file size in MB
+
[Parameter]
public EventCallback OnUpload { get; set; } // optional - executes a method in the calling component when a file is uploaded
@@ -381,16 +390,39 @@
if (uploads.Length > 0)
{
string restricted = "";
+ string tooLarge = "";
foreach (var upload in uploads)
{
- var filename = upload.Split(':')[0];
+ var fileparts = upload.Split(':');
+ var filename = fileparts[0];
+
+ if (MaxUploadFileSize > 0)
+ {
+ var filesizeBytes = long.Parse(fileparts[1]);
+ var filesizeMB = (double)filesizeBytes / (1024 * 1024);
+ if (filesizeMB > MaxUploadFileSize)
+ {
+ tooLarge += (tooLarge == "" ? "" : ",") + filename;
+ }
+ }
+
var extension = (filename.LastIndexOf(".") != -1) ? filename.Substring(filename.LastIndexOf(".") + 1) : "";
if (!PageState.Site.UploadableFiles.Split(',').Contains(extension.ToLower()))
{
restricted += (restricted == "" ? "" : ",") + extension;
}
}
- if (restricted == "")
+ if (restricted != "")
+ {
+ _message = string.Format(Localizer["Message.File.Restricted"], restricted);
+ _messagetype = MessageType.Warning;
+ }
+ else if (tooLarge != "")
+ {
+ _message = string.Format(Localizer["Message.File.TooLarge"], tooLarge, MaxUploadFileSize);
+ _messagetype = MessageType.Warning;
+ }
+ else
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
@@ -490,11 +522,6 @@
tokenSource.Dispose();
}
}
- else
- {
- _message = string.Format(Localizer["Message.File.Restricted"], restricted);
- _messagetype = MessageType.Warning;
- }
}
else
{
diff --git a/Oqtane.Client/Resources/Modules/Controls/FileManager.resx b/Oqtane.Client/Resources/Modules/Controls/FileManager.resx
index c2ccac05..2759abb5 100644
--- a/Oqtane.Client/Resources/Modules/Controls/FileManager.resx
+++ b/Oqtane.Client/Resources/Modules/Controls/FileManager.resx
@@ -144,4 +144,10 @@
Files With Extension Of {0} Are Restricted From Upload. Please Contact Your Administrator For More Information.
+
+ Maximum upload file size: {0} MB
+
+
+ File(s) {0} exceed(s) the maximum upload size of {1} MB
+
\ No newline at end of file