通过API GateWay和Lambada下载xlsx

时间:2019-02-23 08:40:56

标签: scala amazon-web-services aws-lambda aws-api-gateway

我需要使用API​​网关和Lambda(Node.js)下载Excel文件的服务, 当我在本地运行此应用程序时,我返回字节数组及其似乎为lambda的应用程序无法处理这些流,我能够下载具有正确数据的excel,但在AWS中使用相同的代码下载时返回加密值。

Node Js Code :



// Another chunk of data has been recieved, so append it to `str`
 response.on('data', function (chunk) {
            responseString += chunk;
        });

        // The whole response has been received
        response.on('end', function () {
            var jsonResponse;
            if (responseString) {
                try {
                    jsonResponse =responseString;
                } catch (err) {
                    jsonResponse = {message: responseString};
                    response.headers['Content-Type'] = "application/json";
                }
            }

            var output = {
                statusCode: response.statusCode,
                body: jsonResponse),
                headers: response.headers
            };
            context.succeed(output);

}); 

标量代码(我的应用程序),它返回字节数组:

 apiName("Get-Tokens-CSV") {

            val byteOutPutStream =  tokenService.getAllTokensCsv(authentication.clientCode)
            val responseEntity = HttpEntity(
                MediaTypes.`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,
              byteOutPutStream
              )
             complete(responseEntity)
          }
        }

Excel数据,我在下载时会得到这样的数据:

 PK  �{VN               _rels/.rels���j�0��}
    �{㴃1F�^Ơ�2��l%1I,c�[��3�l
    l�����H��4�R�l��·����q}*�2������;�*��
    t"�^�l;1W)�N�iD)ejuD�cKz[׷:}g����@:�
    �3����4�7N�s_ni�G�M*7�����2R�+�   �2�/�����b��mC�Pp�ֱ$POyQ�抒�DsZ��IС�'un���~�PK����   O  PK  �{VN               [Content_Types].xml�SMO1��+6��m��1���G%��β
    �J[���MDL0�S;yo�{3i�Ӎ5�c��5lć�B'��nѰ��S}˪��)0�aÜg��`<�L��԰.�p'D�ZH�t��>Z�Tƅ ��@q=��]F��\4�=`+���P�!-!S.�v�@��+��N�tEV=nHe7���S,;K]_h7Q+�W8߶Z��re��c�U�����}���....

0 个答案:

没有答案