Cloudmersive

Jun 14, 2021

2 min read

Scan GCP Storage Files for Viruses in C/C++

Implementing a consistent and reliable virus scanning process for your GCP storage files can prevent exposure to the increasing list of threats that are targeting cloud storage. By utilizing the following API in C/C++, you will be able to automatically the scan the contents of a single GCP storage file for viruses, malware, ransomware, spyware, and trojans in less time than it takes to say ‘virus scan’.

To kick things off, we will install libcurl into our C/C++ project:

libcurl/7.75.0

With the installation out of the way, we are ready to call our virus scan function with the following example code:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/virus/scan/cloud-storage/gcp-storage/single");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "bucketName: <string>");
headers = curl_slist_append(headers, "objectName: <string>");
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "jsonCredentialFile");
curl_mime_filedata(part, "/path/to/file");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
}
curl_easy_cleanup(curl);

Keep in mind that you will need your GCP bucket name, object name, JSON service account credential file, and API key for a successful response. If you need to obtain an API key, you can do so by registering for a free account on the Cloudmersive website.