Antivirus in Azure using Azure Defender: Synchronously
If you cannot use Azure Defender for Storage, see my earlier post on how to do it with ClamAV
Disclaimer: For asynchronous handling, use storage event grid events: https://learn.microsoft.com/en-us/azure/defender-for-cloud/defender-for-storage-configure-malware-scan
Disclaimer: This is a simplicity focused solution, and it makes any cloud hiccups the users problem - which can be bad in some scenarios. Take that into account!
Step 1: Azure storage at least setup in Standard Tier: Not available in Free tier
Step2: Enable Defender for Storage
The code:
Below is pseudocode in C#
FAQ
How long does the blob tag usually take to appear?
My testing indicates under 3 seconds for most cases
Can you trust the blob tag to appear every time?
No - the only thing you can trust in the cloud is that it will sometimes not work, that means the WaitFor will time out and an error will be made -> just make this clear in the frontend.
How do you recommend using this in a website context?
Handle the slight delay in the frontend with a progress bar that shows clearly that the file is being virus checked - the user should know what is going on
Disable form posting while the file is being uploaded
When users sends 5 files at once, just call the backend upload API 5 times to make each file go in their own thread + stream
What is the timeout for a form POST request?
Configurable in .NET is the answer, both the max request size and max request duration can be configured - they are both important for this use case
builder.WebHost.ConfigureKestrel(o => o.Limits.MaxRequestBodySize = 104857600); builder.Services.Configure<FormOptions>(o => o.MultipartBodyLengthLimit = 104857600);