Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Base64 decoding failed. #10

Open
Dayjo opened this issue Feb 7, 2017 · 1 comment
Open

Base64 decoding failed. #10

Dayjo opened this issue Feb 7, 2017 · 1 comment

Comments

@Dayjo
Copy link

Dayjo commented Feb 7, 2017

Hello, I'm getting the following error response when trying to use this library;

array(1) {
  ["error"]=>
  array(4) {
    ["code"]=>
    int(400)
    ["message"]=>
    string(110) "Invalid value at 'requests[0].image.content' (TYPE_BYTES), Base64 decoding failed for "data:image/jpg;base64,""
    ["status"]=>
    string(16) "INVALID_ARGUMENT"
    ["details"]=>
    array(1) {
      [0]=>
      array(2) {
        ["@type"]=>
        string(41) "type.googleapis.com/google.rpc.BadRequest"
        ["fieldViolations"]=>
        array(1) {
          [0]=>
          array(2) {
            ["field"]=>
            string(25) "requests[0].image.content"
            ["description"]=>
            string(110) "Invalid value at 'requests[0].image.content' (TYPE_BYTES), Base64 decoding failed for "data:image/jpg;base64,""
          }
        }
      }
    }
  }
}

I've tried with multiple files and types (png and jpg) and get the same error.

I'm using the demo code;

$gcv->setImage("public/images/upsell/drinks1.jpg");

// 1 is Max result
$gcv->addFeature("LABEL_DETECTION", 1);

Doesn't seem to be anything I can do to get it to work.

@Dayjo
Copy link
Author

Dayjo commented Feb 7, 2017

So, I've managed to get this to work by getting rid of curl from the base64 decode, and also not using data urls. i.e;

/**
     * @param string $path
     *
     * @return string
     */
    public function convertImgtoBased64($path)
    {
        // $urlParts = pathinfo($path);
        // $extension = $urlParts['extension'];
        // $ch = curl_init();
        // curl_setopt($ch, CURLOPT_URL, $path);
        // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // curl_setopt($ch, CURLOPT_HEADER, 0);
        // $response = curl_exec($ch);
        // curl_close($ch);
        $response = file_get_contents($path);
        $base64 = base64_encode($response);
        return $base64;
    }

This now works..

tegansnyder pushed a commit to tegansnyder/google-cloud-vision-php that referenced this issue Feb 7, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant