Skip to content

Commit 86754a0

Browse files
committed
Editor增加Upload回调
1 parent c0e8878 commit 86754a0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/BootstrapBlazor.Server/Components/Samples/Editors.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@page "/editor"
2+
23
@inject SwalService SwalService
34
@inject PackageVersionService VersionManager
45
@inject IStringLocalizer<Editors> Localizer
6+
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
57

68
<h3>@Localizer["EditorsTitle"]</h3>
79

@@ -38,7 +40,7 @@
3840
</DemoBlock>
3941

4042
<DemoBlock Title="@Localizer["EditorIsEditorTitle"]" Introduction="@Localizer["EditorIsEditorIntro"]" Name="IsEditor">
41-
<Editor IsEditor="true" />
43+
<Editor IsEditor="true" OnFileUpload="OnFileUpload" />
4244
</DemoBlock>
4345

4446
<DemoBlock Title="@Localizer["EditorHeightTitle"]" Introduction="@Localizer["EditorHeightIntro"]" Name="Height">

src/BootstrapBlazor.Server/Components/Samples/Editors.razor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ private async Task InsertHtmlAsync()
111111
await Editor.DoMethodAsync("pasteHTML", $"<h1>{Localizer["DoMethodAsyncPasteHTML"]}</h1>");
112112
}
113113

114+
private async Task<string> OnFileUpload(EditorUploadFile uploadFile)
115+
{
116+
var url = Path.Combine("images", "uploader",
117+
$"{Path.GetFileNameWithoutExtension(uploadFile.FileName)}-{DateTimeOffset.Now:yyyyMMddHHmmss}{Path.GetExtension(uploadFile.FileName)}");
118+
var fileName = Path.Combine(WebsiteOption.CurrentValue.WebRootPath, url);
119+
var ret = await uploadFile.SaveToFile(fileName);
120+
return ret ? url : "";
121+
}
122+
114123
private string? _editorCode;
115124

116125
private async Task OnGetCode()

0 commit comments

Comments
 (0)