Comments (6)
Thanks for reporting! Do you think you could write a failing unit test? Take an attempt at a PR to resolve?
from middy.
I did a little digging, might be related to the Content-Type
header. We use busboy
to parse the request body.
from middy.
Closing due to lack of feedback. Please reopen if adding Content-Type
doesn't resolve the issue.
from middy.
I experience the same issue. I send a PNG file (26,403 bytes) via Postman (multpart/form-data, query_image
is the file) to my local serverless endpoint.
Node: 20.11.0
/ WebPack: 5.89.0
/ Serverless: 3.38.0
If I use the following middy packages: (I also tried with older v4 packages)
@middy/[email protected]
@middy/[email protected]
@middy/[email protected]
Both plugins called before lambdaHandler
via .use()
.
const lambdaHandler = async (event) => {
console.log(event);
...
}
Console result:
{
body: {
query_image: {
filename: 'testImage.png',
mimetype: 'image/png',
encoding: '7bit',
truncated: false,
content: <Buffer c2 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 71 00 00 00 c2 9c 08 06 00 00 00 48 c2 a4 44 c2 8c 00 00 66 c3 aa 49 44 41 54 78 c2 9c c3 ... 39695 more bytes>
}
},
cookies: [],
headers: {
'user-agent': 'PostmanRuntime/7.36.0',
accept: '*/*',
'postman-token': 'cf2cfa05-c351-4ef5-adbf-f06849b5a2e3',
host: 'localhost:3000',
'accept-encoding': 'gzip, deflate, br',
connection: 'keep-alive',
'content-type': 'multipart/form-data; boundary=--------------------------466455162022947297222544',
'content-length': '26620'
},
...
If I use a similar multipart/form-data processor package [email protected]
(npm) I get the correct file size and attachment is processable:
const parser = require('lambda-multipart-parser');
const lambdaHandler = async (event) => {
const result = await parser.parse(event);
console.log(result.files);
...
}
Result:
[
{
content: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 71 00 00 00 9c 08 06 00 00 00 48 a4 44 8c 00 00 66 ea 49 44 41 54 78 9c ed fd 77 bc 64 47 79 ... 26353 more bytes>,
filename: 'testImage.png',
contentType: 'image/png',
encoding: '7bit',
fieldname: 'query_image'
}
]
Both packages use busboy
, slight differences. Not sure what causes the problem.
from middy.
Looking at the two implementations:
lambda-multipart-parser
file.on('data', data => {
uploadFile.content = data;
});
This means it can only handle files up to a certain size.
@middy/http-multipart-body-parser
file.on('data', (data) => {
chunks.push(data)
})
file.on('end', () => {
attachment.content = Buffer.concat(chunks)
})
To support larger files, Buffer.concat
concat is used here.
Note: c2
added at the beginning and every so often for some reason
@paulmaszlik can you create a PR with a unit test?
from middy.
just pass charset: 'binary' to the middleware like this:
httpMultipartBodyParser({
charset: "binary",
})
from middy.
Related Issues (20)
- Http router / path mapping HOT 6
- Not able to invoke the http-router routes from post-man using serverless-offiline HOT 4
- ERR_PACKAGE_PATH_NOT_EXPORTED error HOT 1
- index.d.ts still allows callback based handlers.
- dead links on getting started page HOT 1
- [middy/core] get event input in timeoutEarlyResponse parameter HOT 1
- Throws an error Error [ERR_PACKAGE_PATH_NOT_EXPORTED] HOT 1
- Restrict types to `APIGatewayProxyResultV2` or `APIGatewayProxyResult` HOT 3
- TypeScript compile error in @middy/core 5.2.4 HOT 7
- Lambda throwing `Failed to resolve internal values` in secretsManagerMiddlewareBefore HOT 3
- Simple lib import fails with both `tsx` and `ts-node` HOT 2
- LLRT Support
- TypeScript error when using `S3Handler` type HOT 4
- middy 5.2.5 isn't available on npm HOT 1
- Please give more descriptive error when throwing "Failed to resolve internal values" in secrets-manager module HOT 2
- middy/http-cors disable defaults and don't add headers HOT 1
- Streamified response with empty body ignores other response attributes HOT 3
- `http-error-handler` to support Problem Details (RFC 9457) HOT 1
- http-error-handler : set custom test to return error instead of `statusCode` HOT 2
- http-error-handler: guidance/bug on using lambda-authorizer with v5 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from middy.