阿里云OpenAPI 看起来也没有,为啥这个10s不生效呢?
import ocr_api20210707, as $ocr_api20210707 from '@alicloud/ocr-api20210707';
import as $OpenApi from '@alicloud/openapi-client';
import as $Util from '@alicloud/tea-util';
import Stream from '@alicloud/darabonba-stream';
import as $tea from '@alicloud/tea-typescript';
import axios from "axios";
export class OCRService {
static createClient(): ocr_api20210707 {
let config = new $OpenApi.Config({
accessKeyId: 'xxxxx',
accessKeySecret: 'xxxxx',
opts: {
connectTimeout: 10000,
readTimeout: 10000,
timeout: 10000
}
});
config.endpoint = ocr-api.cn-hangzhou.aliyuncs.com
;
return new ocr_api20210707(config);
}
async recognizeHKIdCard(base64ImageUrl: string) {
let client = OCRService.createClient();
const preSignedUrl = Buffer.from(base64ImageUrl, 'base64').toString('ascii');
const response = await axios.get(preSignedUrl, {
responseType: 'arraybuffer',
});
const imageBuffer = Buffer.from(response.data);
//fix China block the site URL
let bodyStream = Stream.readFromBytes(imageBuffer);
let recognizeHKIdcardRequest = new $ocr_api20210707.RecognizeHKIdcardRequest({
body: bodyStream,
});
let runtime = new $Util.RuntimeOptions({ });
try {
const response = await client.recognizeHKIdcardWithOptions(recognizeHKIdcardRequest, runtime);
const { data } = response.body;
return {
headers: {
'Content-Type': 'application/json'
},
statusCode: 200,
body: data
}
} catch (error) {
return {
headers: {
'Content-Type': 'application/json'
},
statusCode: 500,
body: JSON.stringify(error)
}
}
}
}
代码写错了 就是直接在config下 而不是再包一层opts
https://help.aliyun.com/zh/sdk/developer-reference/configure-a-timeout-period-1?spm=a2c4g.11186623.0.0.13f03a11uKIooK ,此回答整理自钉群“OpenAPI 开发者门户 - 值班服务群2群”
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。