Member-only story
NodeJS: File Upload and Virus Scan
3 min readAug 19, 2019
As part of this guide, I’m going to be uploading a file using the HTML input type file element and scan the uploaded file for virus(es) using the npm module, clamscan.
Prerequisites
- The clamscan module requires the clamdscan or clamav installed on your machine (or the server). If you are not familiar with clamav engine, I highly recommend you read about it first. Additionally, you can follow my guide on how to install clamav and/or clamdscan on Ubuntu.
- A node.js module to parse multipart-form data (I’ve used formidable — multiparty, busboy, multer are some of the well known alternatives).
Uploading the file
There is no surprise in this part to be honest. We will make use of the standard HTML file type input to capture the user’s file. The markup would look like -
<form method="POST" action="/scan-file">
<input type="file" id="field-someDocument" name="someDocument" accept="image/png,image/jpeg,application/pdf">
<input type="submit" value="submit" />
</form>
As you can see, this form on submission will hit the /scan-file
express route which we will get into later.