-1

I want to scan the file content and viruses scanning while uploading file to server.I learnt about ClamAV but not getting any clue how to use it or installation in Angular component.Any help is appreciated.

Anjali
  • 49
  • 5

1 Answers1

0

Clamav runs on Node.js, it won't run on angular. What you can do to check if the file is free of viruses or any malware by uploading the file to temporary location on the server.

You can use Node.js API and the you can run clamscan. There might be other tools too, but this is free and worth using.

npm install clamscan
const NodeClam = require('clamscan');
const ClamScan = new NodeClam().init(options);

// Get instance by resolving ClamScan promise object
ClamScan.then(async clamscan => {
    try {
        // You can re-use the `clamscan` object as many times as you want
        const version = await clamscan.getVersion();
        console.log(`ClamAV Version: ${version}`);

        const {isInfected, file, viruses} = await clamscan.isInfected('/some/file.zip');
        if (isInfected) console.log(`${file} is infected with ${viruses}!`);
    } catch (err) {
        // Handle any errors raised by the code in the try block
    }
}).catch(err => {
    // Handle errors that may have occurred during initialization
});

If you want to use async/await, this code can help:

const NodeClam = require('clamscan');

async some_function() {
    try {
        // Get instance by resolving ClamScan promise object
        const clamscan = await new NodeClam().init(options);
        const {goodFiles, badFiles} = await clamscan.scanDir('/foo/bar');
    } catch (err) {
        // Handle any errors raised by the code in the try block
    }
}

some_function();

check this link for more details on it.

Apoorva Chikara
  • 8,277
  • 3
  • 20
  • 35