2
votes

I'm using the Azure OCR Service to get the text of an image back ( https://docs.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

1
Not sure what you're asking. What do you mean by 'local file'? Blob storage isn't local, nor is File Storage. Are you asking about copying content to a VM / web app? Please edit to clarify.David Makogon

1 Answers

2
votes

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);
});