How to Check a Google Cloud Platform (GCP) File for Viruses in Java

Cloudmersive
2 min readJan 11, 2021

--

When storing essential and confidential business content in a GCP storage file, you want to ensure the content is safe from threats. However, with the vast array of viruses and malware that are floating around in cyberspace, the possibility of an attack on your storage is ever-increasing. The following API can assist you with the security of your content by scanning a single GCP storage file for viruses, malware, trojans, ransomware, and spyware.

To use the Cloudmersive API, install the SDK with Maven by referencing the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Next, add a reference to the dependency in pom.xml:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>

Then, you can call the function by entering the bucket name, object/file name, and JSON service account credential into the following code:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ScanCloudStorageApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
ScanCloudStorageApi apiInstance = new ScanCloudStorageApi();
String bucketName = "bucketName_example"; // String | Name of the bucket in Google Cloud Storage
String objectName = "objectName_example"; // String | Name of the object or file in Google Cloud Storage
File jsonCredentialFile = new File("/path/to/inputfile"); // File | Service Account credential for Google Cloud stored in a JSON file.
try {
CloudStorageVirusScanResult result = apiInstance.scanCloudStorageScanGcpStorageFile(bucketName, objectName, jsonCredentialFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ScanCloudStorageApi#scanCloudStorageScanGcpStorageFile");
e.printStackTrace();
}

In less than a second, our technology scans a continuously updated database of over 17 million virus signatures, returning a result indicating if the file is clean, or the virus name (if found). Head to the Cloudmersive website to gain access to your free API key and 800 monthly calls across our library 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