How to Scan an AWS S3 File for Viruses in JavaScript
Amazon Web Services Simple Storage Service (a.k.a. AWS S3) provides object storage through a web service interface. It is one of the most popular options for cloud storage, and was also one of the first, with competing services popping up to follow suit after AWS S3’s broad adoption. If your business relies on this storage as a secure space for company objects and files, it’s important to ensure that infected files don’t contaminate your content. The following API can be run in JavaScript to scan the contents of an AWS S3 file for viruses and malware; it provides wide file format support as well as multi-threat scanning.
Our first step is to install the jQuery library:
bower install jquery
Next, we need to input a few parameters to ensure the operation runs smoothly including the AWS S# access key, secret key, bucket region, and bucket name. Once we have all our information plugged in, we can call the virus scan function with the following code:
var settings = {
"url": "https://api.cloudmersive.com/virus/scan/cloud-storage/aws-s3/single",
"method": "POST",
"timeout": 0,
"headers": {
"accessKey": "<string>",
"secretKey": "<string>",
"bucketRegion": "<string>",
"bucketName": "<string>",
"keyName": "<string>",
"Apikey": "YOUR-API-KEY-HERE"
},
};$.ajax(settings).done(function (response) {
console.log(response);
});
The result will indicate if any of the contents were identified as threats, and if so, will specify both the infected file name as well as the virus name.