我希望能够在我的网站上实现来自 Project Oxford 的 Emotion API。我目前编写了以下 HTML/JavaScript 代码,它检查来自 URL 的图像并在运行 Emotion API 后显示所述图像的结果:
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<body>
<script type="text/javascript">
$(function() {
$.ajax({
url: "https://api.projectoxford.ai/emotion/v1.0/recognize",
beforeSend: function(xhrObj) {
// Request headers
xhrObj.setRequestHeader("Content-Type", "application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", "my-key");
},
type: "POST",
// Request body
data: '{"url": "https://philosophybank.files.wordpress.com/2013/08/happy-people.jpg"}',
})
.done(function(data) {
JSON.stringify(data);
alert(JSON.stringify(data));
//console.log(data);
//alert(data.scores);
})
.fail(function(error) {
console.log(error.getAllResponseHeaders());
alert("fail");
});
});
</script>
此代码工作正常,但是我希望在我的网站上实现这一点,以便人们使用浏览按钮从他们的机器本地上传图像,而不是使用链接查找图像。任何帮助将不胜感激!