Reputation: 47
I'm using the Azure OCR Service to get the text of an image back ( https://learn.microsoft.com/de-de/azure/cognitive-services/Computer-vision/quickstarts/javascript#OCR).
So far everything is up and running, but now I would like to use a local file instead of an already uploaded one.
// Display the image.
var sourceImageUrl = document.getElementById("inputImage").value;
document.querySelector("#sourceImage").src = sourceImageUrl;
// Perform the REST API call.
$.ajax({
url: uriBase + "?" + $.param(params),
// Request headers.
beforeSend: function(jqXHR){
jqXHR.setRequestHeader("Content-Type","application/json");
jqXHR.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
},
type: "POST",
// Request body.
data: '{"url": ' + '"' + sourceImageUrl + '"}',
})
.done(function(data) {
// Show formatted JSON on webpage.
$("#responseTextArea").val(JSON.stringify(data, null, 2));
})
I tried
Upvotes: 2
Views: 1369
Reputation: 9950
The code you posted is JavaScript, not Node.js.
Here is an example of analyzing a local image using Node.js with request module:
var request = require('request');
var fs = require('fs');
var options = {
url: 'https://westus.api.cognitive.microsoft.com/vision/v1.0/analyze',
qs: {
visualFeatures: 'Categories',
details: '',
language: 'en'
},
headers: {
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': '<key>'
},
body: fs.readFileSync('./Shaki_waterfall.jpg')
};
request.post(options, function (error, response, body) {
console.log(body);
});
Upvotes: 3