- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够在我的网站上实现 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>
这段代码工作正常,但是我希望在我的网站上实现这一点,以便人们使用浏览按钮从他们的机器本地上传图像,而不是使用链接查找图像。任何帮助将非常感激!
最佳答案
我使用 application/octet-stream
作为正文类型来模拟它,它允许您发布二进制对象(即图像本身),而不是图像的 url。 Emotion API documentation详细说明了这是如何受支持的内容类型。
我按照您原来的示例继续使用 JQuery。
您应该能够将整个示例复制并粘贴到 HTML 文件中,在显示 my-key
的位置添加您的 Emotion API key ,它将起作用
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<input type="file" id="file" name="filename">
<button id="btn">Click here</button>
<script type="text/javascript">
$('#btn').click(function () {
var file = document.getElementById('file').files[0];
$.ajax({
url: "https://api.projectoxford.ai/emotion/v1.0/recognize",
beforeSend: function(xhrObj) {
// Request headers
xhrObj.setRequestHeader("Content-Type", "application/octet-stream");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", "my-key");
},
type: "POST",
data: file,
processData: false
})
.done(function(data) {
JSON.stringify(data);
alert(JSON.stringify(data));
})
.fail(function(error) {
alert(error.getAllResponseHeaders());
});
});
</script>
</body>
</html>
关于javascript - 实现 Microsoft 的 Project Oxford - Emotion API 和文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35565732/
我正在尝试在利用 Emotion 的 React 项目中使用本地托管字体及其 Global component .此方法适用于网络字体,例如 Google Fonts ,但是当我下载相同的字体并尝试将
在 Emotion v10 中,文档说“如果您从 @emotion/css/macro 导入它,则有一个 Babel 宏可用于来自 @emotion/core 的 css。”这显然适用于无法更改 ba
我正在使用 @emotion/react主题并将主题注入(inject)其中,我可以使用 useTheme 访问主题到组件中,但无法使用 @emotion/styled 将主题访问到样式中.请问有什么
我正在尝试使用 React Emotion设置一条水平线,中间有文本。它看起来像这样: ----------------------SOME TEXT-------------------------
运行 React 测试库以在使用 Emotion css 属性的 JSX 上生成快照,导致没有渲染任何 CSS。 我试过使用“@emotion/jest/serializer”,但仍然没有运气。 组件
在 Emotion 11 之前的版本中,我曾经像这样在开发中禁用 CSS 前缀: const emotionCache = createCache({ prefix: process.env.NO
我想设计两个按钮的样式:使用情感 css 使用图像向上和向下,但无法这样做。目前,我通常在函数中设置元素的样式。如何使用情感 css 实现这一目标? 我关注了 https://emotion.sh/d
我正在将我的应用程序的样式从 Less 转换为 Emotion 在 Less 中我有如下样式: @blue: #476882; background: rgba(red(@blue), green(@
我正在为我的应用创建聊天功能,我们有一组自定义表情符号。 如果用户在他们的评论中键入其中一个表情的快捷方式,我们需要能够检测到快捷方式按出现顺序并用适当的表情替换它们。 例如。 let emotes
我知道这与 Target another styled component on hover 非常相似 不过我想用emotion-js达到同样的效果 更具体地说,我正在尝试重新创建 this使用情感风
我正在尝试在 Emotion 中创建可重复使用的动画但遇到了一些问题。我为 fadeUp 定义了一个动画。效果很好。 export const animatedFadeUp = css` opac
在决定何时使用样式化组件而不是 css prop 时,是否有最佳实践或优缺点列表? 最佳答案 我通常更喜欢 styledComponent但是,有一些极端情况,比如为 设置样式对于 react-ro
我要安装neumorphism-react包裹。 但我得到了这个错误 Module not found: Can't resolve '@emotion/react' in'C:\Users\Asus
如果我安装 emotion那么 API 很好而且很清晰: 包.json: "dependencies": { "emotion": "^10.0.9", react 组件: import Reac
我使用 @emotion\styled 声明了以下样式按钮: const Button = styled.button` background: blue; ${size({ width: p
我目前正在开发一个不和谐的机器人,我试图在嵌入消息中显示自定义服务器表情,它应该出现在“插入表情图标”中,但我无法完成它。这是否可能?如果可能,如何实现? if (member.hasPermissi
我正在使用 Affectiva 的 Emotion SDK for Javascript 来播放和分析视频文件。目前,我正在以流的形式播放视频,并按照 "Analyze a video frame s
在元素中,我遇到了使用 Emotion 实现的 CSS-IN-JS。通常,我都是通过CSS样式的名称来查找对应组件的代码,但是由于生成的样式名称,我在元素代码中尝试从浏览器中查找元素时感到很痛苦。 实
在我维护的设计系统中,我们使用修改后的 BEM 格式来命名导出的 @emotion/css JSS 样式。 语法看起来像这样: Selector_descendant___modifier 例如(伪代
我想使用来自 react-emotion 的样式来使用 HighChartWrapper 包装 HighchartsReact。 下面是我正在尝试的伪代码。 import HighchartsReac
我是一名优秀的程序员,十分优秀!