无间AR云识别服务支持在浏览器上使用Javascript访问,无需设置代理配置跨域。
支持上传文件与使用Base64图片数据访问识别接口。
实例下载: https://github.com/wujianar/image-search-javascript
官网: www.wujianar.cn
开发者中心: portal.wujianar.cn
// data为FormData或JSON字符串,如 {"image": "/9j/4AAQ..."}
function httpPost(data) {
let headers = new Headers({ 'Authorization': '这里是认证token' });
if (!(data instanceof FormData)) {
headers.append('content-type', 'application/json');
}
return window.fetch('https://iss-api.wujianar.cn/search', {
method: 'POST',
headers: headers,
body: data
}).then(res => res.json());
}
// file为HTML的file对象
function searchByFile(file) {
const data = new FormData();
data.append('file', file);
return httpPost(data);
}
// image为base64编码数据,将状况信息去掉后再发送
function searchByBase64(image) {
const data = { image: image.split('base64,').pop() };
return httpPost(JSON.stringify(data));
}