From ff6bd0dede33535a38626c9e5dd17965e48a232a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 6 Aug 2025 19:29:24 +0800 Subject: [PATCH] refactor: add FileName check --- .../Components/Download/Download.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/BootstrapBlazor/Components/Download/Download.cs b/src/BootstrapBlazor/Components/Download/Download.cs index 787a592d944..b6639ac7d56 100644 --- a/src/BootstrapBlazor/Components/Download/Download.cs +++ b/src/BootstrapBlazor/Components/Download/Download.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using System; + namespace BootstrapBlazor.Components; /// @@ -38,13 +40,13 @@ protected virtual async Task DownloadFromStream(DownloadOption option) throw new InvalidOperationException($"the {nameof(option.FileStream)} is null"); } -#if NET5_0 - // net 5.0 not support - await Task.CompletedTask; -#elif NET6_0_OR_GREATER + if (string.IsNullOrEmpty(option.FileName)) + { + throw new InvalidOperationException($"the {nameof(option.FileName)} is null or empty"); + } + using var streamRef = new DotNetStreamReference(option.FileStream); await InvokeVoidAsync("downloadFileFromStream", option.FileName, streamRef); -#endif } /// @@ -59,6 +61,11 @@ protected virtual async Task DownloadFromUrl(DownloadOption option) throw new InvalidOperationException($"{nameof(option.Url)} not set"); } + if (string.IsNullOrEmpty(option.FileName)) + { + throw new InvalidOperationException($"the {nameof(option.FileName)} is null or empty"); + } + await InvokeVoidAsync("downloadFileFromUrl", option.FileName, option.Url); }