2017-09-04 75 views
1

如果我想通过nodejs为API配置binaryMediaTypes ['image/jpg','text/html']。什么是正确的API使用?它看起来像下面的不工作。使用javascript SDK更新aws apigateway binaryMediaTypes

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'); 
       } 
      }); 
     }); 

回答

0

我们最终使用updateRestApi()。请注意patchOpertions部分,这是非常不直观的(可以提高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'); 
      } 
     });