How to scan a file for viruses in Ruby

Cloudmersive
1 min readAug 9, 2019

--

Viruses can be a huge problem, but how can they be dealt with easily and reliably? Well, there’s an API for that. Start by adding the virus scan client to your Gemfile.

gem 'cloudmersive-virus-scan-api-client', '~> 1.3.0'

Then run scan_file:

# load the gem
require 'cloudmersive-virus-scan-api-client'
# setup authorization
CloudmersiveVirusScanApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
end
api_instance = CloudmersiveVirusScanApiClient::ScanApi.newinput_file = File.new("/path/to/file") # File | Input file to perform the operation on.begin
#Scan a file for viruses
result = api_instance.scan_file(input_file)
p result
rescue CloudmersiveVirusScanApiClient::ApiError => e
puts "Exception when calling ScanApi->scan_file: #{e}"
end

And that’s really all there is to it. Your output will consist of positive/negative and the item’s identity in the case of a positive.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet