in imagesearch-20200212/ts/src/client.ts [698:752]
async addImageAdvance(request: AddImageAdvanceRequest, runtime: $Util.RuntimeOptions): Promise<AddImageResponse> {
// Step 0: init client
let accessKeyId = await this._credential.getAccessKeyId();
let accessKeySecret = await this._credential.getAccessKeySecret();
let authConfig = new $RPC.Config({
accessKeyId: accessKeyId,
accessKeySecret: accessKeySecret,
type: "access_key",
endpoint: "openplatform.aliyuncs.com",
protocol: this._protocol,
regionId: this._regionId,
});
let authClient = new OpenPlatform(authConfig);
let authRequest = new $OpenPlatform.AuthorizeFileUploadRequest({
product: "ImageSearch",
regionId: this._regionId,
});
let authResponse = await authClient.authorizeFileUploadWithOptions(authRequest, runtime);
// Step 1: request OSS api to upload file
let ossConfig = new $OSS.Config({
accessKeyId: authResponse.accessKeyId,
accessKeySecret: accessKeySecret,
type: "access_key",
endpoint: RPCUtil.getEndpoint(authResponse.endpoint, authResponse.useAccelerate, this._endpointType),
protocol: this._protocol,
regionId: this._regionId,
});
let ossClient = new OSS(ossConfig);
let fileObj = new $FileForm.FileField({
filename: authResponse.objectKey,
content: request.picContentObject,
contentType: "",
});
let ossHeader = new $OSS.PostObjectRequestHeader({
accessKeyId: authResponse.accessKeyId,
policy: authResponse.encodedPolicy,
signature: authResponse.signature,
key: authResponse.objectKey,
file: fileObj,
successActionStatus: "201",
});
let uploadRequest = new $OSS.PostObjectRequest({
bucketName: authResponse.bucket,
header: ossHeader,
});
let ossRuntime = new $OSSUtil.RuntimeOptions({ });
RPCUtil.convert(runtime, ossRuntime);
await ossClient.postObject(uploadRequest, ossRuntime);
// Step 2: request final api
let addImagereq = new AddImageRequest({ });
RPCUtil.convert(request, addImagereq);
addImagereq.picContent = `http://${authResponse.bucket}.${authResponse.endpoint}/${authResponse.objectKey}`;
let addImageResp = await this.addImage(addImagereq, runtime);
return addImageResp;
}