Member-only story

NodeJS: File Upload and Virus Scan

Nikhil Nanjappa
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

  1. 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.
  2. A node.js module to parse multipart-form data (I’ve used formidablemultiparty, 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.

Handling Multipart-form data

--

--

Nikhil Nanjappa
Nikhil Nanjappa

Written by Nikhil Nanjappa

Experienced Full-Stack Developer who loves sharing knowledge. Gaming & Music addict. Always grateful and looking for new experiences in life.

Responses (3)