问题
I started with this example.
... ended up with this failing code.
I wanted to return a simple pdf file.
I find that SLS is not converting to binary.
Here is the serverless.yml file.
functions:
hello:
handler: handler.hello
description: Can we display a PDF?
events:
- http:
path: hello
method: get
contentHandling: CONVERT_TO_BINARY
plugins:
- serverless-apigw-binary
- serverless-apigwy-binary
custom:
apigwBinary:
types:
- 'application/pdf'
And here is the handler
'use strict';
var fs = require('fs');
module.exports.hello = (event, context, callback) => {
fs.readFile("templates/i-130.pdf", function (err, data) {
callback(null, {
statusCode: 200,
headers: {'Content-Type': 'application/pdf'},
body: JSON.stringify({
message: data.toString('base64')
})
});
});
};
The problems I see are:
- content is NOT converted to binary
- header is NOT set to application/pdf
How can this be fixed?
AND for the sake of others, can you just fix the code so it works?
来源:https://stackoverflow.com/questions/54317704/how-to-do-serverless-binary-configuration-right