Skip to content Skip to sidebar Skip to footer

Ibm Watson Api Of Visual Recognition Add Image Issue In Collectio Using Curl

I am using IBM watson visual recognition api when I add an image to collection but I receive following error always: string(59) '{ 'error': 'Missing multipart/form-data', 'code':

Solution 1:

I have review your code and make some changes and now its working.

if (isset($_FILES['uploadedfile']) && $_POST != "") {
    $targetPath = 'uploads/' . basename($_FILES['uploadedfile']['name']);
    $url = 'https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key={your_key}&version=2016-05-20';
    $post_data = array(
        'file' =>
        '@' . $_FILES['uploadedfile']['tmp_name']
        . ';filename=' . $_FILES['uploadedfile']['name']
        . ';type=' . $_FILES['uploadedfile']['type']
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $headers = array();
    $headers[] = "Content-Type: multipart/form-data";
    $headers[] = "Accept: application/json";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
        die;
    }
    var_dump($result, true);
    die;
}

Post a Comment for "Ibm Watson Api Of Visual Recognition Add Image Issue In Collectio Using Curl"