Maximum upload file size parameter for FileManager
This commit is contained in:
@@ -61,6 +61,12 @@
|
|||||||
{
|
{
|
||||||
<input type="file" id="@_fileinputid" name="file" accept="@_filter" />
|
<input type="file" id="@_fileinputid" name="file" accept="@_filter" />
|
||||||
}
|
}
|
||||||
|
@if (MaxUploadFileSize > 0)
|
||||||
|
{
|
||||||
|
<div class="row my-1">
|
||||||
|
<small class="fw-light">@string.Format(Localizer["File.MaxSize"], MaxUploadFileSize)</small>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<button type="button" class="btn btn-success" @onclick="UploadFiles">@SharedLocalizer["Upload"]</button>
|
<button type="button" class="btn btn-success" @onclick="UploadFiles">@SharedLocalizer["Upload"]</button>
|
||||||
@@ -163,6 +169,9 @@
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public int ChunkSize { get; set; } = 1; // optional - size of file chunks to upload in MB
|
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]
|
[Parameter]
|
||||||
public EventCallback<int> OnUpload { get; set; } // optional - executes a method in the calling component when a file is uploaded
|
public EventCallback<int> OnUpload { get; set; } // optional - executes a method in the calling component when a file is uploaded
|
||||||
|
|
||||||
@@ -381,16 +390,39 @@
|
|||||||
if (uploads.Length > 0)
|
if (uploads.Length > 0)
|
||||||
{
|
{
|
||||||
string restricted = "";
|
string restricted = "";
|
||||||
|
string tooLarge = "";
|
||||||
foreach (var upload in uploads)
|
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) : "";
|
var extension = (filename.LastIndexOf(".") != -1) ? filename.Substring(filename.LastIndexOf(".") + 1) : "";
|
||||||
if (!PageState.Site.UploadableFiles.Split(',').Contains(extension.ToLower()))
|
if (!PageState.Site.UploadableFiles.Split(',').Contains(extension.ToLower()))
|
||||||
{
|
{
|
||||||
restricted += (restricted == "" ? "" : ",") + extension;
|
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();
|
CancellationTokenSource tokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
@@ -490,11 +522,6 @@
|
|||||||
tokenSource.Dispose();
|
tokenSource.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
_message = string.Format(Localizer["Message.File.Restricted"], restricted);
|
|
||||||
_messagetype = MessageType.Warning;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -144,4 +144,10 @@
|
|||||||
<data name="Message.File.Restricted" xml:space="preserve">
|
<data name="Message.File.Restricted" xml:space="preserve">
|
||||||
<value>Files With Extension Of {0} Are Restricted From Upload. Please Contact Your Administrator For More Information.</value>
|
<value>Files With Extension Of {0} Are Restricted From Upload. Please Contact Your Administrator For More Information.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="File.MaxSize" xml:space="preserve">
|
||||||
|
<value>Maximum upload file size: {0} MB</value>
|
||||||
|
</data>
|
||||||
|
<data name="Message.File.TooLarge" xml:space="preserve">
|
||||||
|
<value>File(s) {0} exceed(s) the maximum upload size of {1} MB</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
Reference in New Issue
Block a user