Scan an AWS S3 File for Viruses in Swift

Cloudmersive
2 min readApr 8, 2021

Utilizing AWS S3 for cloud storage allows you to efficiently manage data with the knowledge that you will be provided with superior service and availability. However, cloud storage files have increasingly become a target for cyberattacks; once the contents have been infiltrated by a virus or other form of malware, the infection can easily spread to other systems and users, causing a whole mess of issues. To avoid this situation, you can utilize the following API in Swift to automatically scan an single AWS S3 file and its content for viruses. This software references over 17 million threat signatures and is continuously updated in the cloud to ensure new threats aren’t missed.

To cue up the process, you simply need to input your AWS S3 access key, secret key, bucket name, bucket region, and key (file) name along with your API key into the following code:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)var request = URLRequest(url: URL(string: "https://api.cloudmersive.com/virus/scan/cloud-storage/aws-s3/single")!,timeoutInterval: Double.infinity)
request.addValue("<string>", forHTTPHeaderField: "accessKey")
request.addValue("<string>", forHTTPHeaderField: "secretKey")
request.addValue("<string>", forHTTPHeaderField: "bucketRegion")
request.addValue("<string>", forHTTPHeaderField: "bucketName")
request.addValue("<string>", forHTTPHeaderField: "keyName")
request.addValue("YOUR-API-KEY-HERE", forHTTPHeaderField: "Apikey")
request.httpMethod = "POST"let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()

Our high-speed in-memory scanning ensures that your result will be delivered to you instantly. If you need to retrieve your personal API key, you can head to Cloudmersive website to register for a free account; this will give you access to 800 monthly calls across our multitude of APIs.

--

--

Cloudmersive

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