How to virus scan an HTML file in Javascript

HTML files can be particularly dangerous when it comes to potential malware threats and script attacks. You need a way to deal with incoming files safely and thoroughly. That’s where our virus scanning API comes in. One call and you have more than 17 million virus definitions at your disposal.

To begin, set up the client by using this script tag, which can be placed either in your page or HTML file, between the head tags.

<script src="https://cdn.cloudmersive.com/jsclient/cloudmersive-virus-client.js"></script>

With our client imported, we are now able to use the scanFile function, demonstrated here:

var CloudmersiveVirusApiClient = require('cloudmersive-virus-api-client');var defaultClient = CloudmersiveVirusApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveVirusApiClient.ScanApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.scanFile(inputFile, callback);

Now all that’s left to do is drop in your file and wait for the results. Very large or heavily compressed files can delay the process.

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store