【问题标题】:How to use Clam AV in Angular 11 version如何在 Angular 11 版本中使用 Clam AV
【发布时间】:2021-10-25 17:52:01
【问题描述】:

我想在将文件上传到服务器时扫描文件内容和病毒扫描。我了解了 ClamAV,但不知道如何使用它或在 Angular 组件中安装。感谢任何帮助。

【问题讨论】:

  • Clamav 在 Node.js 上运行,它不会在 Angular 上运行。

标签: angular antivirus angular11 virus-scanning clamav


【解决方案1】:

Clamav 在 Node.js 上运行,它不会在 Angular 上运行。您可以通过将文件上传到服务器上的临时位置来检查文件是否没有病毒或任何恶意软件。

您可以使用 Node.js API 并且可以运行 clamscan。可能还有其他工具,但这是免费的,值得使用。

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
});

如果您想使用 async/await,此代码可以提供帮助:

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();

查看this链接了解更多详情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-23
    • 2013-09-10
    • 2021-07-13
    • 2021-07-05
    • 2020-07-13
    • 2022-11-03
    • 1970-01-01
    • 2019-11-05
    相关资源
    最近更新 更多