-
Notifications
You must be signed in to change notification settings - Fork 1
/
simpleVision.js
40 lines (33 loc) · 917 Bytes
/
simpleVision.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict'
require('dotenv').config()
const request = require('request')
const subscriptionKey = process.env.KEY
const endpoint = process.env.ENDPOINT
if (!subscriptionKey) { throw new Error() }
var uriBase = endpoint + 'vision/v3.0/analyze'
const imageUrl =
'https://upload.wikimedia.org/wikipedia/commons/3/3c/Shaki_waterfall.jpg'
// Request parameters.
const params = {
visualFeatures: 'Categories,Description,Color',
details: '',
language: 'en'
}
const options = {
uri: uriBase,
qs: params,
body: '{"url": ' + '"' + imageUrl + '"}',
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscriptionKey
}
}
request.post(options, (error, response, body) => {
if (error) {
console.log('Error: ', error)
return
}
const jsonResponse = JSON.stringify(JSON.parse(body), null, ' ')
console.log('JSON Response\n')
console.log(jsonResponse)
})