2
votes

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?

2
I added an answer below - but what does webContentLink return? Is that a file URL?Mike Jeffrey
As a workaround, the 'thumbnailLink' works surprisingly well w/ Cloud Vision. You need to remove the '=s220' from the URI though.Matt
drive.google.com/uc?id=xxxx also fails even when public, it is as if drive detects the cloud vision and blocks it.tofutim

2 Answers

1
votes

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.
0
votes

Agree with Mike, I also did some research on Google App Script to Vision API, since they are all under Google umbrella, so I made a wrong assumption that they could "talk" to each other (that is why I found this post). But it could not work. I believe that is the nature of Google Vision API.

Just little bit add-on to Mike's answer, if you pass the authentication (I believe you have to go through this, since you need to upload the file to Google Storage), then you might not need to specify the file to be public to be used in your application.