Tusdotnet 是为使用 .NET 核心实现进行文件上传而构建的,其尺寸较大(如果万一卡住,将从同一点恢复)。
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
我需要问:
在与 Tusdotnet 进行调查后,我发现只有两个选择:
第一种方法
文件夹系统中文件上传成功后,对文件进行重命名。 (由于 tusdotnet 上传成功后不会保留文件扩展名。
第二种方法
同时,当 tusdotnet 成功上传文件时,请使用以下代码上传带有扩展名的相同文件:
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);
}
}
}
参考:
您好,如果您解决了这个问题,可以与我们分享吗?