- Notifications
You must be signed in to change notification settings - Fork73
.NET server implementation of the Tus protocol for resumable file uploads. Read more athttps://tus.io
License
tusdotnet/tusdotnet
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
"Our aim is to solve the problem of unreliable file uploads once and for all. tus is a new open protocol for resumable uploads built on HTTP. It offers simple, cheap and reusable stacks for clients and servers. It supports any language, any platform and any network." -https://tus.io
tusdotnet is a .NET server implementation of the tus.io protocol that runs on .NET Framework, .NET Standard, .NET6 and later.
Comments, ideas, questions and PRs are welcome!
- Runs on .NET Framework, .NET Standard 1.3+ and .NET 6+ using OWIN or ASP.NET Core
- Full support for tus 1.0.0 including all major extensions (checksum, checksum-trailers, concatenation, creation, creation-with-upload, upload-defer-length, expiration and termination)
- Experimental support for IETF'sResumable Uploads For Http (see branchPOC/tus2)
- Fast and reliable
- Easy to configure
- Customizable data storage
- MIT licensed
Visual Studio
PM> Install-Package tusdotnet
.NET CLI
> dotnet add package tusdotnet
On .NET6 and later:
usingtusdotnet;varbuilder=WebApplication.CreateBuilder(args);varapp=builder.Build();app.MapTus("/files",async httpContext=>new(){// This method is called on each request so different configurations can be returned per user, domain, path etc.// Return null to disable tusdotnet for the current request.// Where to store data?Store=newtusdotnet.Stores.TusDiskStore(@"C:\tusfiles\"),Events=new(){// What to do when file is completely uploaded?OnFileCompleteAsync=async eventContext=>{tusdotnet.Interfaces.ITusFilefile=awaiteventContext.GetFileAsync();Dictionary<string,tusdotnet.Models.Metadata>metadata=awaitfile.GetMetadataAsync(eventContext.CancellationToken);usingStreamcontent=awaitfile.GetContentAsync(eventContext.CancellationToken);awaitDoSomeProcessing(content,metadata);}}});
Depending on your infrastructure you might also need toconfigure Kestrel,IIS orother reverse proxies.
More options and events are available on thewiki.
Create your Startup class as you would normally do. Add a using statement fortusdotnet
and runUseTus
on the app builder. Depending on your infrastructure you might also need toconfigure Kestrel,IIS orother reverse proxies. More options and events are available on thewiki.
app.UseTus(httpContext=>newDefaultTusConfiguration{// This method is called on each request so different configurations can be returned per user, domain, path etc.// Return null to disable tusdotnet for the current request.// c:\tusfiles is where to store filesStore=newTusDiskStore(@"C:\tusfiles\"),// On what url should we listen for uploads?UrlPath="/files",Events=newEvents{OnFileCompleteAsync=async eventContext=>{ITusFilefile=awaiteventContext.GetFileAsync();Dictionary<string,Metadata>metadata=awaitfile.GetMetadataAsync(eventContext.CancellationToken);usingStreamcontent=awaitfile.GetContentAsync(eventContext.CancellationToken);awaitDoSomeProcessing(content,metadata);}}});
If you just want to play around with tusdotnet/the tus protocol, clone the repo and run one of the test sites. They each launch a small site running tusdotnet and theofficial JS client so that you can test the protocol on your own machine.
Test sites are available for:
- ASP.NET Core 6 (.NET 6.0)
- ASP.NET Core 3.1 (.NET Core 3.1)
- ASP.NET Core 3.0 (.NET Core 3.0)
- ASP.NET Core 2.2 (.NET Core 2.2)
- ASP.NET Core 2.2 (.NET Framework 4.6.2)
- ASP.NET Core 2.1 (.NET Core 2.1)
- OWIN (.NET Framework 4.5.2)
tus.io keeps a list of clients for a number of different platforms (Android, Java, JS, iOS etc). tusdotnet should work with all of them as long as they support version 1.0.0 of the protocol.
This project is licensed under the MIT license, seeLICENSE.
About
.NET server implementation of the Tus protocol for resumable file uploads. Read more athttps://tus.io