Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private async Task SaveToFile(UploadFile file)
_token ??= new CancellationTokenSource();
try
{
var ret = await file.SaveToFileAsync(fileName, MaxFileLength, _token.Token);
var ret = await file.SaveToFileAsync(fileName, MaxFileLength, token: _token.Token);

if (ret)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private async Task SaveToFile(UploadFile file)
_token ??= new CancellationTokenSource();
try
{
var ret = await file.SaveToFileAsync(fileName, MaxFileLength, _token.Token);
var ret = await file.SaveToFileAsync(fileName, MaxFileLength, token: _token.Token);

if (ret)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.8.0-beta05</Version>
<Version>9.8.0-beta06</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions src/BootstrapBlazor/Extensions/UploadFileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public static async Task RequestBase64ImageFileAsync(this UploadFile upload, str
/// <param name="upload"></param>
/// <param name="fileName"></param>
/// <param name="maxAllowedSize"></param>
/// <param name="bufferSize"></param>
/// <param name="token"></param>
/// <returns></returns>
[ExcludeFromCodeCoverage]
public static async Task<bool> SaveToFileAsync(this UploadFile upload, string fileName, long maxAllowedSize = 512000, CancellationToken token = default)
public static async Task<bool> SaveToFileAsync(this UploadFile upload, string fileName, long maxAllowedSize = 512000, int bufferSize = 64 * 1024, CancellationToken token = default)
{
var ret = false;
if (upload.File != null)
Expand Down Expand Up @@ -92,15 +93,15 @@ public static async Task<bool> SaveToFileAsync(this UploadFile upload, string fi
{
// 打开文件流
var stream = upload.File.OpenReadStream(maxAllowedSize, token);
var buffer = new byte[4 * 1096];
var buffer = new byte[bufferSize];
int bytesRead = 0;
double totalRead = 0;

// 开始读取文件
while ((bytesRead = await stream.ReadAsync(buffer, token)) > 0)
{
totalRead += bytesRead;
await uploadFile.WriteAsync(buffer.AsMemory(0, bytesRead), token);
await uploadFile.WriteAsync(buffer, 0, bytesRead, token);

if (upload.UpdateCallback != null)
{
Expand Down