Search code examples
google-cloud-vision

google Cloud Vision API: vision.detectText() does not accept a google drive v3 URI


vision.detectText() chokes when handed a URI presented by google drive v3 in webviewLink format obtained from drive.files.get()

my webViewLink grabber is:

drive.files.get({
  auth: auth,
  fileId: options.fileID,
  //fields: 'webContentLink'  // <-- downloads the file
  fields: 'webViewLink'       // <-- "views" the file
},function(err, response) {}

response.webViewLink is in the format:

https://drive.google.com/file/d/0Bw4DMtLCtPMkOTlXR1l4Nkw1WGs/view?usp=drivesdk

vision.detectText(response.webViewLink) chokes with:

ERROR: { PartialFailureError: A failure occurred during this request.
at /Users/node_modules/@google-cloud/vision/src/index.js:434:15
at /Users/node_modules/@google-cloud/vision/src/index.js:126:5
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
errors: 
[ { image:  'https://drive.google.com/file/d
/0Bw4DMtLCtPMkOTlXR1l4Nkw1WGs/view?usp=drivesdk',
errors: [Object] } ],
response: { responses: [ [Object] ] },
message: 'A failure occurred during this request.' }

replacing that webViewLink URI with a 'traditional' form (like http://www.identifont.com/samples/houseindustries/NeutraText.gif) works fine.

Please note that https://cloud.google.com/vision/docs/request#providing_the_image sez that "You can provide the image in your request ... As a publicly-accessible HTTP or HTTPS URL".

Should the Drive v3 webViewLink format count as "publicly-accessible" for vision.detectText()?

If not, how should this format be modified to be acceptable to vision.detectText() to support evaluation of images hosted by google drive?


Solution

  • While this is a publicly-accessible URL, unfortunately it's the URL to a page which has the image embedded in it, rather than the URL of the image file itself.

    So you can't use a Google Drive URL in your request. Your easiest option might be Google Cloud Storage... there's a web UI to upload your images, here:

    https://console.cloud.google.com/storage/browser

    From that page, you'd:

    1. Click Create bucket and follow the instructions (you can accept the defaults, you just need to create a globally unique bucket name).
    2. Click Upload a file and select your image.
    3. Once uploaded, select the checkbox next to the file and click Share publicly.
    4. Click on Public link (on the same line as the file) to get the public URL.