StefanOssendorf.Blazor.DirectUploadInput 0.0.0-prev.0.15

This is a prerelease version of StefanOssendorf.Blazor.DirectUploadInput.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package StefanOssendorf.Blazor.DirectUploadInput --version 0.0.0-prev.0.15
NuGet\Install-Package StefanOssendorf.Blazor.DirectUploadInput -Version 0.0.0-prev.0.15
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StefanOssendorf.Blazor.DirectUploadInput" Version="0.0.0-prev.0.15" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StefanOssendorf.Blazor.DirectUploadInput --version 0.0.0-prev.0.15
#r "nuget: StefanOssendorf.Blazor.DirectUploadInput, 0.0.0-prev.0.15"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StefanOssendorf.Blazor.DirectUploadInput as a Cake Addin
#addin nuget:?package=StefanOssendorf.Blazor.DirectUploadInput&version=0.0.0-prev.0.15&prerelease

// Install StefanOssendorf.Blazor.DirectUploadInput as a Cake Tool
#tool nuget:?package=StefanOssendorf.Blazor.DirectUploadInput&version=0.0.0-prev.0.15&prerelease

DirectFileUpload

A Blazor (WASM) component designed/intended for directly uploading large files (>500MB) without going into the C# part.

Why?

Since I needed to upload large files at my work with blazor to our servers I hit the problem that WASM Blazor does not support uploading large files through the C# part to the servers. This is due to the fact that the HttpClient buffers the whole file into an array. (For information see this ASP.Net core issue)

How to use?

The following is an example on how to use all features provided by the DirectFileUpload component. You can find a locally running example in the tests-folder.

@using StefanOssendorf.Blazor.DirectUploadInput

<DirectFileUpload @ref="@FileUpload" UploadSettings="@UploadSettings" Multiple="true" Accept="image/jpeg" StrictAccept="true" UploadStarting="@UploadingCallback" FilesUploaded="@UploadFinishedCallback" FileUploadErrored="@UploadeErrored" FileUploadCanceled="@UploadCanceled" />


@code {
    // Configuration for the settings used for uploading
	private FileUploadSettings UploadSettings {
		get;
	} = new FileUploadSettings {
			HttpMethod = "POST",
			UploadUrl = "api/uploads",
			FormName = "files",
			Headers = new Dictionary<string, string>()
		};

	private FileUploadStarting? _startUploading;
    // Callback which will be invoked immediately before the actual upload starts with information about the files being uploaded.
	private async void UploadingCallback(FileUploadStarting data) {
		_startUploading = data;

        // Used to reset the example UI
        _fileUploadCanceled = _cancelMessage = string.Empty;
		_fileUploadResult = null;
		_fileUploadError = null;

		await InvokeAsync(StateHasChanged).ConfigureAwait(false);
	}

	private FileUploadResult? _fileUploadResult;
    // Callback which will be invoked when the upload response got back with the data as a pure string.
	private async Task UploadFinishedCallback(FileUploadResult uploadResult) {
		_fileUploadResult = uploadResult;
		await InvokeAsync(StateHasChanged).ConfigureAwait(false);
	}

	private string _cancelMessage = string.Empty;
	private DirectFileUpload FileUpload { get; set; } = null!;

    // Method to be invoked e.g. by user interaction to cancel a currently running file upload	
    private async Task CancelUpload(){
		await FileUpload.CancelUpload().ConfigureAwait(false);
		_cancelMessage = "Upload canceled";
		await InvokeAsync(StateHasChanged).ConfigureAwait(false);
	}

	private FileUploadError _fileUploadError;

    //	Callback which will be invoked when any kind of error occurred. 
    // ATTENTION: This does not include 3XX,4XX or 5XX responses. These will be handled by the "upload finished" callback!
    private async Task UploadeErrored(FileUploadError fileUploadError) {
		_fileUploadError = fileUploadError;
		await InvokeAsync(StateHasChanged).ConfigureAwait(false);
	}

	private string _fileUploadCanceled = string.Empty;
	
    // Callback which will be invoked when the cancellation was done.
    private async Task UploadCanceled() {
		_fileUploadCanceled = "Upload was canceled";
		await InvokeAsync(StateHasChanged).ConfigureAwait(false);
	}
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.0-prev.0.31 220 5/3/2022
0.0.0-prev.0.29 109 4/24/2022
0.0.0-prev.0.28 186 3/15/2022
0.0.0-prev.0.25 276 11/22/2021
0.0.0-prev.0.22 187 10/20/2021
0.0.0-prev.0.19 138 10/12/2021
0.0.0-prev.0.17 219 10/10/2021
0.0.0-prev.0.15 146 10/9/2021