Scan Image URL

This function is used when the image data is to be downloaded from an image URL. It returns a JSON protocol that contains the result(s) for each category.

 

URL

https://iavis.image-analyzer.com/image_url

 

JSON Payload

{

                "token": "Unique token id",

                "category_ids":

                [

                                 "This parameter will contain the comma separated list of category ids.",

                ]

                "image_url": "This parameter will contain URL of image."

}

 

JSON Payload Example

{

                "token":"6d4b6a83-debd-43dc-8c21-0e2fcea2a812",

                "category_ids":

                [

                                 "5934",

                                 "1863",

                                 "5214",

                                 "3081"

                ],

                "image_url":"http:\/\/b0b1df7540eac2ba583fe6c7fa8c101e.lswcdn.net\/48457_thumbnail.jpg"

}

 

JSON Response

{

                "scan_result":

                [

                                 {

                                                 "category_name": "Result"

                                 }

                 ],

                 "error_code": "Error code in case the result is false",

                 "result": "true or false i.e. success or failure of scanning."

}

 

JSON Response Example

{

                "scan_result":

                [

                                 {

                                                 "Terrorism": "0.000786812786813"

                                 },

                                 {

                                                 "Weapons": "0.273313824852"

                                 },

                                 {

                                                 "Porn": "99.999"

                                 },

                                 {

                                                 "Gore": "7.53667953668"

                                 }

                ],

                "error_code": "",

                "result": "True"

}

 

Sample Code

Below is the sample code that can be used for scanning an image data using the REST Interface

 

PHP:

 

<?php

    $strToken = "token string";

    $strImageData =  base64_encode(file_get_contents('/home/ubuntu/testimage.gif'));

 

    $data = array("token" => $strToken,  "category_ids" => array('category_id1', 'category_id2'), "binary_image_data" => $strImageData);                                                                   

    $data_string = json_encode($data);

 

    $ch = curl_init("https://iavis.image-analyzer.com/image_data");

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");    

    curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          

    'Content-Type: json/image_data',                                                                               

    'Content-Length: ' . strlen($data_string)));

 

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);

    var_dump($response);

?>

 

PERL:

 

use strict;

use MIME::Base64;

use REST::Client;

use JSON;

 

my $strToken = "<token>";

my $file = "/home/ubuntu/testimage.gif";

 

my $imagedata= do {

    local $/ = undef;

    open my $fh, "<", $file

        or die "could not open $file: $!";

    <$fh>;

};

my $encoded_data = encode_base64($imagedata);

 

my $client = REST::Client->new();

 

my @categories = ('category id1', 'category id2');

 

my %data = ("token" => $strToken, "category_ids" => \@categories, "binary_image_data" => $encoded_data);

my $data_string = encode_json \%data;

 

$client->setHost("https://iavis.image-analyzer.com");

 

my $response = $client->POST("/image_data", $data_string);

print $client->responseContent(), "\n";

 

PYTHON:

 

import requests

import base64

import json

import numpy as np

 

def jdefault(o):

    return o.__dict__

 

strToken = "<token>";

arrCategories = ['category id1', 'category id2']

strFileName = "/home/ubuntu/testimage.gif"

imagefile = np.fromfile(strFileName, dtype='int16', sep="")

encodedImagefile = base64.b64encode(imagefile)

base64_string = encodedImagefile.decode('utf-8')

post_data = {"token": strToken, "category_ids": arrCategories, "binary_image_data": base64_string}

 

response = requests.post("https://iavis.image-analyzer.com/image_data",data=json.dumps(post_data))

token_json = response.json()

print(json.dumps(token_json))

 

C#:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Net;

using System.IO;

 

namespace Sample_ImageData

{

    class Program

    {

        static void Main(string[] args)

        {

            string strTocken = "<token>";

            string strCategoryID = "[\"category id1\", \"category id2\"]";

            string strImageFilePath = "D:\\Images\\testimage.gif";

 

            byte[] buff = null;

                        FileStream fs = new FileStream(strImageFilePath,

                                                            FileMode.Open,

                                                            FileAccess.Read);

                        BinaryReader br = new BinaryReader(fs);

                        long numBytes = new FileInfo(strImageFilePath).Length;

                        buff = br.ReadBytes((int) numBytes);

                        string strBase64ImageData = System.Convert.ToBase64String(buff);

 

            string strjson = "{\"token\":\"" + strTocken + "\"," + "\"category_ids\"" + ":" + strCategoryID + "," + "\"binary_image_data\"" + ":\"" + strBase64ImageData + "\"}";

                        byte[] byteArray = Encoding.UTF8.GetBytes(strjson);

            string strJSONUrl = "https://iavis.image-analyzer.com/image_data";

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strJSONUrl);

                        req.Timeout = 100000000;

                        req.Method = "POST";

                        req.ContentLength = byteArray.Length;

                        Stream dataStream = req.GetRequestStream();

                        dataStream.Write(byteArray, 0, byteArray.Length);

                        WebResponse response = req.GetResponse();

                        dataStream = response.GetResponseStream();

                        StreamReader reader = new StreamReader(dataStream);

                        string Result = reader.ReadToEnd();

                        reader.Close();

                        dataStream.Close();

                        response.Close();

            if (string.Empty != Result)

            {

                Console.WriteLine(Result);

                Console.ReadLine();

            }

        }

    }

}

 

Was this answer helpful?

 Print this Article

Also Read

Scan Image Data

This function is used when the image data is to be uploaded. It returns a JSON protocol that...

Authentication

IA ViS requires the calling application to supply authentication credentials as ‘AUTHORIZATION’...

Interpreting Results

Image Analyzer ViS supports the classification of images for multiple threat categories. The scan...

Error Codes

  -1 = Username Empty or Invalid -2 = Password Empty or Invalid -3 = Not Enough Scan tokens...