How to Scan a Google Cloud Platform (GCP) Storage File in Node.JS

Cloudmersive
2 min readJan 7, 2021

--

With the ever-changing and evolving threats to cloud storage, it’s vital that you take steps to ensure your data is safe. If you have a virus that is undetected, there’s a chance it could seep into other critical applications, or even be downloaded by users, which would be detrimental to both your business and the users. The following API allows you to be proactive by scanning your GCP file in Node.JS for multiple threats at one time.

To begin the process, you can run this command to install the SDK:

npm install cloudmersive-virus-api-client -–save

Or, add this snippet to your package.json:

  "dependencies": {
"cloudmersive-virus-api-client": "^1.1.7"
}

Then, we are calling the function with the following code; please note you will need the bucket name, object/file name, and JSON credential file as well.

var CloudmersiveVirusApiClient = require('cloudmersive-virus-api-client');
var defaultClient = CloudmersiveVirusApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveVirusApiClient.ScanCloudStorageApi();var bucketName = "bucketName_example"; // String | Name of the bucket in Google Cloud Storagevar objectName = "objectName_example"; // String | Name of the object or file in Google Cloud Storagevar jsonCredentialFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Service Account credential for Google Cloud stored in a JSON file.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.scanCloudStorageScanGcpStorageFile(bucketName, objectName, jsonCredentialFile, callback);

In no time at all, this will return a response which will specify the virus name (if detected) or that your GCP file is currently out of harm’s way. In order to retrieve the free API Key, visit the Cloudmersive website; this will give you access to 800 monthly calls across our portfolio of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet