我目前正在开发一种病毒扫描功能。
我想要做的事情:当文件上传到指定的 blob 存储容器时,会触发 Azure 函数。该函数将扫描文件是否有病毒,如果没有病毒,则将文件移动到另一个 Blob 存储容器。
我创建了一个 Azure 函数,该函数在创建 blob 时(即上传文件时)触发,但我不知道如何将病毒扫描集成到其中。
我尝试使用ClamAV.js ,但我无法让它工作。我不确定如何安装 ClamAV(守护进程),以便 Azure 函数可以使用它,因此这可能是它不起作用的原因。另外,我不确定如何安装 npm 包(在 Azure 函数中),因此我必须将实际的 js 文件从包上传到函数,然后导入它。不确定这是否有效......
我尝试过使用AttachmentScanner ,但我无法在 Azure 函数中使用它(更具体地说,我无法让该函数发送 POST 请求)。
我面临的一个我认为无法解决的主要问题:如何在 Azure Functions 中使用 npm 包?我可以 npm 安装它们吗?我可以直接下载包并手动将js文件上传到Azure Function并以这种方式导入吗?
这是我使用 AttachmentScanner 的尝试:
module.exports = async function (context, myBlob) {
var req = new XMLHttpRequest();
req.open( "POST", "https://beta.attachmentscanner.com/requests", false );
req.headers({
"authorization": "bearer [OMITTED]",
"content-type": "application/json"
});
req.type("json");
req.send({
"url": context.bindingData.uri //"http://www.attachmentscanner.com/eicar.com"
});
req.end(function (res) {
if (res.error) throw new Error(res.error);
context.log(req.responseText);
});
context.log("JavaScript blob trigger function processed blob \n Name:", context.bindingData.name, "\n Blob Size:", myBlob.length, "Bytes");
context.log("context");
context.log(context);
context.log("myBlob");
context.log(myBlob);
};
这会产生错误:异常:ReferenceError:XMLHttpRequest未定义
通过以下函数,我可以检测 blob 并打印有关它的信息:
module.exports = async function (context, myBlob) {
context.log("JavaScript blob trigger function processed blob \n Name:", context.bindingData.name, "\n Blob Size:", myBlob.length, "Bytes");
context.log("context");
context.log(context);
context.log();
context.log("myBlob");
context.log(myBlob);
};
感谢任何帮助!
最佳答案
首先,我确定你无法安装ClamAV到 Azure Functions 中,因此您需要创建一个 Linux VM 来安装它。
接下来,您可以按照官方快速入门教程进行操作,例如 Visual Studio Code , Azure CLI , Python或Linux安装Azure Functions Core Tool在 Windows 或 Linux 的本地环境中为 Node.js 创建 func 项目并将其发布到 Azure。
最后,根据您的需求,这是我自己的想法。您可以尝试将 Azure Function 与 Blob 触发器结合使用,为需要扫描的 Blob 生成带有 sas token 的 url。有一个代码示例Node.js Azure Function for generating SAS tokens
你所指的知道如何做。然后,通过带有 ClamAV.js 的 Node.js 服务器将带有 sas token 的 blob url 传递到 VM 中的 ClamAV,以使用 HTTP 流对其进行扫描。
当然,您可以将 ClamAV.js 与 Azure Functions 集成,但我认为对于像 Azure Functions 这样的无服务器架构来说,长时间扫描大文件并不是一个好主意。希望对您有所帮助。
关于javascript - Azure:如何在传入的 blob/文件进入 blob 存储之前对其进行扫描?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55605732/