How to scan a file for viruses in Salesforce Apex
Need an advanced virus scanning solution for your Apex project? We’ve got you covered. Our API can provide you cloud-updated coverage with over 17 million definitions and counting. And the best part is, you will be up and running in just a few minutes.
Let’s get started by opening our project folder and extracting our API client into it.
Now we can proceed to call the scanFile function, as demonstrated below:
SwagScanApi api = new SwagScanApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'inputFile' => Blob.valueOf('Sample text file\nContents')};try {// cross your fingersSwagVirusScanResult result = api.scanFile(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}
And then our result will be returned to us like so:
{
"CleanResult": true,
"FoundViruses": [
{
"FileName": "string",
"VirusName": "string"
}
]
}
Easy. No more virus scanning worries!
