Tusdotnet is built for File uploads with .NET core Implementations, which are larger in size (If in case its gets stuck it will be resume from the same point).
app.UseTus(httpContext => new DefaultTusConfiguration
{
// c:\tusfiles is where to store files
Store = new TusDiskStore(@"C:\tusfiles\"),
// On what url should we listen for uploads?
UrlPath = "/files",
Events = new Events
{
//OnFileCompleteAsync = eventContext =>
OnFileCompleteAsync = async eventContext =>
{
//return Task.CompletedTask;
ITusFile file = await eventContext.GetFileAsync();
if (file != null)
{
//Convert in to a FileStream
//var fileStream = await file.GetContentAsync(httpContext.RequestAborted);
}
}
}
}
https://github.com/tusdotnet/tusdotnet
I need to ask that:
After investigating with Tusdotnet I found only two options:
First Approach
Renaming of file when the file is successfully uploaded in the folder system. (As tusdotnet not maintain file extension when its upload successfully.
Second Approach
Parallelly when tusdotnet upload your file successfully, upload same file with extension as well by using below code:
OnFileCompleteAsync = async eventContext =>
{
ITusFile file = await eventContext.GetFileAsync();
if (file != null)
{
var fileStream = await file.GetContentAsync(httpContext.RequestAborted);
var metadata = await file.GetMetadataAsync(httpContext.RequestAborted);
httpContext.Response.ContentType = metadata.ContainsKey("contentType")
? metadata["contentType"].GetString(Encoding.UTF8)
: "application/octet-stream";
//Providing New File name with extension
string name = "NewFileName.jpg";
string networkPath = @"C:\tusfiles\";
using (var fileStream2 = new FileStream(networkPath + "\\" + name, FileMode.Create, FileAccess.Write))
{
await fileStream.CopyToAsync(fileStream2);
}
}
}
Reference: