<!DOCTYPE html> <html> <head> <title>Analyze Sample</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> </head> <body> <script type="text/javascript"> function processImage() { // ********************************************** // *** Update or verify the following values. *** // ********************************************** // Replace the subscriptionKey string value with your valid subscription key. var subscriptionKey = "13hc77781f7e4b19b5fcdd72a8df7156"; // Replace or verify the region. // // You must use the same region in your REST API call as you used to obtain your subscription keys. // For example, if you obtained your subscription keys from the westus region, replace // "westcentralus" in the URI below with "westus". // // NOTE: Free trial subscription keys are generated in the westcentralus region, so if you are using // a free trial subscription key, you should not need to change this region. var uriBase = "https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/analyze"; // Request parameters. var params = { "visualFeatures": "Categories,Description,Color", "details": "", "language": "en", }; // 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(xhrObj){ xhrObj.setRequestHeader("Content-Type","application/json"); xhrObj.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)); }) .fail(function(jqXHR, textStatus, errorThrown) { // Display error message. var errorString = (errorThrown === "") ? "Error. " : errorThrown + " (" + jqXHR.status + "): "; errorString += (jqXHR.responseText === "") ? "" : jQuery.parseJSON(jqXHR.responseText).message; alert(errorString); }); }; </script> <h1>Analyze image:</h1> Enter the URL to an image of a natural or artificial landmark, then click the <strong>Analyze image</strong> button. <br><br> Image to analyze: <input type="text" name="inputImage" id="inputImage" value="http://upload.wikimedia.org/wikipedia/commons/3/3c/Shaki_waterfall.jpg" /> <button onclick="processImage()">Analyze image</button> <br><br> <div id="wrapper" style="width:1020px; display:table;"> <div id="jsonOutput" style="width:600px; display:table-cell;"> Response: <br><br> <textarea id="responseTextArea" class="UIInput" style="width:580px; height:400px;"></textarea> </div> <div id="imageDiv" style="width:420px; display:table-cell;"> Source image: <br><br> <img id="sourceImage" width="400" /> </div> </div> </body> </html>
Image to analyze: <input type="text" name="inputImage" id="inputImage" value="http://upload.wikimedia.org/wikipedia/commons/3/3c/Shaki_waterfall.jpg" />
type="text"を type="file"
にして、fileを添付して分析をできるようにしたいのですがうまくいきません。どうすればよいでしょうか。
引用 https://docs.microsoft.com/ja-jp/azure/cognitive-services/computer-vision/quickstarts/javascript