this is a question I also asked on the tusdotnet git forum. I extend my reach here so I could probably get a wide variety of responses and suggestions.
I am new to using the tus upload protocol, currently trying to build a new upload mechanism to replace the existing one in my aspnet mvc solution. I am using the netcore 3.1. So as stated on the git forum, I am trying to find a possibility to override or re-set the destination of my file upload. The old upload mechanism is able to dynamically set the upload destination based on the HttpContext query parameter objects, while on the tusdotnet, I see we basically set the file upload destination during the initial object configuration in our startup pipeline. Is it possible to override this every moment we post a file?
Here is the source code containing the example of tus upload configuration to give the context
app.UseTus(context => new DefaultTusConfiguration
{
UrlPath = "/files",
Store = new TusDiskStore(@"C:\tusfiles\"), //I want to override or re-set the value per every upload requests
Events = new Events
{
OnBeforeCreateAsync = ctx => //Trying to find the initial event that gets called when we send upload request (cmiiw)
{
string uploadDir = GetUploadStoreDir(eventCtx.HttpContext.Request.Query);
ctx.Store = GetUploadDir(eventCtx.HttpContext.Request.Query); //re-set the value here
if (!Directory.Exists(Path.GetFullPath(uploadDir))) Directory.CreateDirectory(uploadDir);
return Task.CompletedTask;
},
OnFileCompleteAsync = async eventContext =>
{
// eventContext.FileId is the id of the file that was uploaded.
// eventContext.Store is the data store that was used (in this case an instance of the TusDiskStore) //how can I use the same dynamic value?
// A normal use case here would be to read the file and do some processing on it.
ITusFile file = await eventContext.GetFileAsync();
var result = await BuildFilePlacementAsync(file, eventContext.Store);
if (!result.Success)
{
throw new MyProcessingException("Something went wrong during processing");
}
}
}
});
I have tried to override the Store from inside one of the event which got something to do with the initial upload process (cmiiw) like OnBeforeCreateAsync
or OnAuthorizeAsync
but none of them seems to do the trick so far.