Skip to content

Latest commit

 

History

History
26 lines (23 loc) · 831 Bytes

Processing-a-file-once-the-file-upload-is-complete.md

File metadata and controls

26 lines (23 loc) · 831 Bytes

tusdotnet supports processing of a file once it has been completed using the OnFileCompleteAsync callback.

app.UseTus(httpContext => new DefaultTusConfiguration
{
	Store = new TusDiskStore(@"C:\tusfiles\"),
	UrlPath = "/files",
	Events = new Events
	{
		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)

			// 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 DoSomeProcessing(file, eventContext.CancellationToken);

			if (!result.Success)
			{
				throw new MyProcessingException("Something went wrong during processing");
			}
		}
	}
});
``