Skip to content

Vision 'detect' method doesn't return values when image is remote url #2087

Description

@talkaboutdesign

When passing in local image url API works great. When passing remote image url api does not provide any results. Here is my code for reference:

'use strict'

// Imports the Google Cloud client library
const Vision = require('@google-cloud/vision');

// Your Google Cloud Platform project ID
const projectId = 'my-id-is-here';

// Instantiates a client
const visionClient = Vision({
  projectId: projectId,
  keyFilename: 'service.json'
});

var img = 'https://d13yacurqjgara.cloudfront.net/users/995236/screenshots/3024565/day-36-normal.png';
var types = ['label','properties'];

visionClient.detect(img, types, function(err, detection, apiResponse) {
    // console.log(detection['labels']);
    // console.log(detection['properties']['colors']);

    if (err) throw err
    console.log(JSON.stringify(apiResponse, null, 2))
});

Activity

  1. talkaboutdesign commented on Mar 15, 2017

    @talkaboutdesign
    Author

    Here is the error I get.

    PartialFailureError: A failure occurred during this request.
        at node_modules/@google-cloud/vision/src/index.js:420:15
        at node_modules/@google-cloud/vision/src/index.js:121:5
        at _combinedTickCallback (internal/process/next_tick.js:74:11)
        at process._tickCallback (internal/process/next_tick.js:98:9)
    
    

    FYI this is running on local machine.

  2. stephenplusplus commented on Mar 15, 2017

    @stephenplusplus
    Contributor

    The API is returning an error for that image:

    {
      code: 500,
      message: 'image-annotator::error(12): We can not access the URL currently. Please download the image and pass it in.'
    }

    To access this error:

    console.log(err.errors[0].errors)

    I know that's pretty goofy, but the layering of err is:

    • err: PartialFailureError - Since the API accepts multiple images and multiple annotation types, some can fail, while others can succeed. We return these in a single argument, the error to the callback
      • errors - This array holds the errors
        • errors[0] - This is the first error of the partial failure
          • image - This lets you know what image the error is referencing
          • errors - There can be multiple reasons why the error occurred (perhaps it was a straight-up 500 like in this case, or an image was unfit for the requested annotation type)
            • errors[0] - The actual error from the API
              • code - The HTTP response status code
              • message - The HTTP response status message
              • type - The detection type that was requested (e.g. labels)

    Sorry for the confusion.

    As far as why Vision cannot access the URL, I'm not sure-- could you open the question on StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform+google-cloud-vision? Googlers from the various service APIs look through those questions and are usually pretty quick to respond.

  3. added
    api: visionIssues related to the Cloud Vision API.
    type: questionRequest for information or clarification. Not an issue.
    on Mar 15, 2017
  4. talkaboutdesign commented on Mar 15, 2017

    @talkaboutdesign
    Author

    Thank you. That helps.

  5. talkaboutdesign commented on Mar 15, 2017

    @talkaboutdesign
    Author

    Is it possible to send base64 encoded image through the detect api in node instead of file name?

  6. stephenplusplus commented on Mar 15, 2017

    @stephenplusplus
    Contributor

    Yep, if provided as a buffer, either like:

    var image = new Buffer('...', 'base64')

    Here's an example with request:

    request('image-url', { encoding: null /* returns a Buffer */ }, function(err, resp, body) {
      vision.detect(body, ['label','properties'], function(err, detection, apiResponse) {})
    })
  7. Jasonspd commented on Apr 12, 2017

    @Jasonspd

    I was detecting remote URL images with an older version of google cloud and it worked fine. However since google cloud 0.50.0, google-cloud has been deprecated.
    npm WARN deprecated [email protected]: The google-cloud meta-package is not recommended; install individual packages.

    I now get the same error as you with remote URL images when using the new way to access vision: @google-cloud/vision

    I may be sticking with the older version until this issue is solved.

    npm install google-cloud --save
    var gcloud = require('google-cloud');
    var vision = gcloud.vision();
    
  8. sthielen commented on Jul 15, 2017

    @sthielen

    I've been having the same issue starting yesterday (7/14), specifically with passing the URL of an image being served from AWS Cloudfront (something like: https://screenshots.cdn.gometa.io/A5A74799-8D42-44E4-8D5D-D54BA1B92CD9.jpg). The problem is intermittent & I cannot consistently reproduce. Sometimes it works for an hour, then goes back to failing with that 500 error.

    Temporarily solved on our end by fetching the image and passing the buffer instead of the remote URL, but wanted to comment letting you folks know. It could easily be an issue with regard to the CDN, but I don't have enough exposure into the error to understand why the fetch is failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api: visionIssues related to the Cloud Vision API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions