Skip to content

Commit 1ef4c10

Browse files
authored
Merge pull request dherault#402 from njriordan/binary-support-with-lambda-integration
Add binary support when using lambda integration
2 parents aded15b + f785a37 commit 1ef4c10

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"Matt Jonker (https://github.com/msjonker)",
7373
"Michael MacDonald (https://github.com/mjmac)",
7474
"Miso (Mike) Zmiric (https://github.com/mzmiric5)",
75+
"Niall Riordan (https://github.com/njriordan)",
7576
"Norimitsu Yamashita (https://github.com/nori3tsu)",
7677
"Oliv (https://github.com/obearn)",
7778
"Paul Esson (https://github.com/thepont)",

src/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ class Offline {
584584
let result = data;
585585
let responseName = 'default';
586586
const responseContentType = endpoint.responseContentType;
587+
const contentHandling = endpoint.contentHandling;
587588

588589
/* RESPONSE SELECTION (among endpoint's possible responses) */
589590

@@ -731,7 +732,14 @@ class Offline {
731732
override: false, // Maybe a responseParameter set it already. See #34
732733
});
733734
response.statusCode = statusCode;
734-
response.source = result;
735+
if (contentHandling === 'CONVERT_TO_BINARY') {
736+
response.encoding = 'binary';
737+
response.source = Buffer.from(result, 'base64');
738+
response.variety = 'buffer';
739+
}
740+
else {
741+
response.source = result;
742+
}
735743
}
736744
else if (integration === 'lambda-proxy') {
737745
response.statusCode = statusCode = result.statusCode || 200;
@@ -742,7 +750,7 @@ class Offline {
742750
if (!_.isUndefined(result.body)) {
743751
if (result.isBase64Encoded) {
744752
response.encoding = 'binary';
745-
response.source = new Buffer(result.body, 'base64');
753+
response.source = Buffer.from(result.body, 'base64');
746754
response.variety = 'buffer';
747755
}
748756
else {

0 commit comments

Comments
 (0)