Code examples
Shell
curl -d '{"stream": true, "bucket": "elm-bucket-virus-scan", "key": "test/virus_test.txt"}' -H 'Content-Type: application/json' http://172.31.39.37:8080/api/clamav/scan/s3/object
Python
import requests
import json
def elm_scan_object(url, stream, bucket, key):
# Define the payload as a dictionary
payload = {
"stream": stream,
"bucket": bucket,
"key": key
}
# Set the headers
headers = {
"Content-Type": "application/json"
}
# Send a POST request to the API endpoint
response = requests.post(url, data=json.dumps(payload), headers=headers)
# Check the response status code
if response.status_code == 200:
# Request was successful
data = response.json() # Extract the JSON data from the response
return data
else:
# Request was not successful
print(f"Request failed with status code: {response.status_code}")
return None
if __name__ == '__main__':
result = elm_scan_object(
url = "http://172.31.39.37:8080/api/clamav/scan/s3/object", \
stream = True, \
bucket = 'elm-bucket-virus-scan', \
key = 'virus_test.txt')
if result:
print(result)
print(result['code'])
print(result['message'])
JavaScript
const axios = require('axios');
async function elmScanObject(url, stream, bucket, key) {
try {
const payload = {
stream,
bucket,
key,
};
const headers = {
'Content-Type': 'application/json',
};
const response = await axios.post(url, payload, { headers });
if (response.status === 200) {
return response.data;
} else {
console.log(`Request failed with status code: ${response.status}`);
return null;
}
} catch (error) {
console.error('An error occurred:', error.message);
return null;
}
}
async function main() {
const url = 'http://172.31.39.37:8080/api/clamav/scan/s3/object';
const stream = true;
const bucket = 'elm-bucket-virus-scan';
const key = 'virus_test.txt';
const result = await elmScanObject(url, stream, bucket, key);
if (result) {
console.log(result);
console.log(result.code);
console.log(result.message);
}
}
main();
Dart
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<Map<String, dynamic>?> elmScanObject(String url, bool stream, String bucket, String key) async {
try {
final payload = {
'stream': stream,
'bucket': bucket,
'key': key,
};
final headers = {
'Content-Type': 'application/json',
};
final response = await http.post(Uri.parse(url), headers: headers, body: jsonEncode(payload));
if (response.statusCode == 200) {
return jsonDecode(response.body);
} else {
print('Request failed with status code: ${response.statusCode}');
return null;
}
} catch (error) {
print('An error occurred: $error');
return null;
}
}
void main() async {
final url = 'http://172.31.39.37:8080/api/clamav/scan/s3/object';
final stream = true;
final bucket = 'elm-bucket-virus-scan';
final key = 'virus_test.txt';
final result = await elmScanObject(url, stream, bucket, key);
if (result != null) {
print(result);
print(result['code']);
print(result['message']);
}
}
Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func elmScanObject(url string, stream bool, bucket string, key string) (map[string]interface{}, error) {
payload := map[string]interface{}{
"stream": stream,
"bucket": bucket,
"key": key,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payloadBytes))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode == http.StatusOK {
var data map[string]interface{}
err = json.Unmarshal(respBody, &data)
if err != nil {
return nil, err
}
return data, nil
} else {
return nil, fmt.Errorf("Request failed with status code: %d", resp.StatusCode)
}
}
func main() {
url := "http://172.31.39.37:8080/api/clamav/scan/s3/object"
stream := true
bucket := "elm-bucket-virus-scan"
key := "virus_test.txt"
result, err := elmScanObject(url, stream, bucket, key)
if err != nil {
fmt.Println("An error occurred:", err)
return
}
if result != nil {
fmt.Println(result)
fmt.Println(result["code"])
fmt.Println(result["message"])
}
}