使用javascript SDK更新aws apigateway binaryMediaTypes

时间:2017-09-04 08:31:47

标签: aws-api-gateway

如果我想通过nodejs为API配置binaryMediaTypes ['image / jpg','text / html']。什么是正确的API使用?看起来下面的内容不起作用。

const config = JSON.stringify({
            "swagger": "2.0",
            "info": {
                "title": this.apiName
            },
            "x-amazon-apigateway-binary-media-types": [ 'image/jpg', 'text/html' ]
        });
        return new Promise((resolve, reject) => {
            var params = {
                restApiId: apiId, /* required */
                mode: 'merge',
                body: config
            };
            this.apiGatewaySDK.putRestApi(params, (err, data) => {
                if (err) {
                    reject(err);
                }
                else {
                    resolve('binary set successfully');
                }
            });
        });

1 个答案:

答案 0 :(得分:0)

我们最终使用updateRestApi()。请注意patchOpertions部分,它非常不直观(sth aws sdk可以改进吗?)

        let patchOperationsArray = [];
        patchOperationsArray.push(
            {
                op: 'add',
                path: '/binaryMediaTypes/'+ e.replace("/", "~1")
            }
        );

        const params = {
            restApiId: apiId, /* required */
            patchOperations:patchOperationsArray
        };
        this.apiGatewaySDK.updateRestApi(params, (err, data) => {
            if (err) {
                reject(err);
            }
            else {
                this.serverless.cli.log('API Gateway Configuring: Binary support are set correctly');
                resolve('binary set successfully');
            }
        });