H5 Web云识别调用(Javascript)

无间AR云识别服务支持在浏览器上使用Javascript访问,无需设置代理配置跨域。
支持上传文件与使用Base64图片数据访问识别接口。

实例下载: https://github.com/wujianar/image-search-javascript

官网: www.wujianar.cn

开发者中心: portal.wujianar.cn

1. 网络请求使用fetch,也可以使用其它Ajax类库,如JQuery等

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

1. 上传文件识别

// file为HTML的file对象
function searchByFile(file) {
    const data = new FormData();
    data.append('file', file);
    return httpPost(data);
}

2. Base64图片识别

// image为base64编码数据,将状况信息去掉后再发送
function searchByBase64(image) {
    const data = { image: image.split('base64,').pop() };
    return httpPost(JSON.stringify(data));
}