Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. To check file for malware using Java, we offer two sample code snippets using different method. Methods includes using OkHttp
, and Unirest
.
REPLACE_ME
with your API key.location
value in payload with url location of your file.callback
value in payload to your webhook url. We recommend using webhook.site as a callback url during test.For 2 and 3, you can find this documented at Offical Documentation
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, """
{
"location": "https://filescanapi.com/icon.png",
"metadata": {
"filename": "demo.png"
},
"callback": "https://webhook.site"
}
""");
Request request = new Request.Builder()
.url("https://api.filescanapi.com/v1/file/async")
.method("POST", body)
.addHeader("x-api-key", "REPLACE_ME")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://api.filescanapi.com/v1/file/async")
.header("x-api-key", "REPLACE_ME")
.header("Content-Type", "application/json")
.body("""
{
"location": "https://filescanapi.com/icon.png",
"metadata": {
"filename": "demo.png"
},
"callback": "https://webhook.site"
}
""")
.asString();