Scan an Azure Blob for Viruses in C#
We’ve seen some incredible advancements in our technology driven era, but along with the benefits come challenges; it seems like every day we hear about a new virus, malware, or spyware attack. If you’re utilizing an Azure Blob for file storage, you can leverage the following API using C# to ensure your content is free from threats. This API is kept current with continuous cloud-based updates to ensure you receive the most accurate and secure scan possible.
To use the Cloudmersive API, we have both .NET Framework and .NET Core SDKs available for installation, but for this example we will be using .NET Framework:
Install-Package Cloudmersive.APIClient.NET.VirusScan -Version 3.0.3
Then, call the function with the following code:
using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.VirusScan.Api;
using Cloudmersive.APIClient.NET.VirusScan.Client;
using Cloudmersive.APIClient.NET.VirusScan.Model;namespace Example
{
public class ScanCloudStorageScanAzureBlobExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");var apiInstance = new ScanCloudStorageApi();
var connectionString = connectionString_example; // string | Connection string for the Azure Blob Storage Account; you can get this connection string from the Access Keys tab of the Storage Account blade in the Azure Portal.
var containerName = containerName_example; // string | Name of the Blob container within the Azure Blob Storage account
var blobPath = blobPath_example; // string | Path to the blob within the container, such as 'hello.pdf' or '/folder/subfolder/world.pdf'try
{
// Scan an Azure Blob for viruses
CloudStorageVirusScanResult result = apiInstance.ScanCloudStorageScanAzureBlob(connectionString, containerName, blobPath);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ScanCloudStorageApi.ScanCloudStorageScanAzureBlob: " + e.Message );
}
}
}
}
And before you can blink, your result will be ready! At this point you can relax with the knowledge that your Azure Blob is virus-free or take action against the identified virus if not.