@middy/http-multipart-body-parser 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -65
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -36,70 +36,6 @@
|
|
|
36
36
|
<p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/http-multipart-body-parser">https://middy.js.org/docs/middlewares/http-multipart-body-parser</a></p>
|
|
37
37
|
</div>
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
Automatically parses HTTP requests with content type `multipart/form-data` and converts the body into an
|
|
41
|
-
object. Also handles gracefully broken JSON as UnprocessableEntity (422 errors)
|
|
42
|
-
if used in combination with `httpErrorHandler`.
|
|
43
|
-
|
|
44
|
-
It can also be used in combination with validator so that the content can be validated.
|
|
45
|
-
|
|
46
|
-
**Note**: by default this is going to parse only events that contain the header `Content-Type` (or `content-type`) set to `multipart/form-data`. If you want to support different casing for the header name (e.g. `Content-type`) then you should use the [`httpHeaderNormalizer`](#httpheadernormalizer) middleware before this middleware.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## Install
|
|
51
|
-
|
|
52
|
-
To install this middleware you can use NPM:
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
npm install --save @middy/http-multipart-body-parser
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
## Options
|
|
60
|
-
|
|
61
|
-
- `busboy` (object) (default `{}`): it can be used to pass extraparameters to the internal `busboy` instance at creation time. Checkout [the official documentation](https://www.npmjs.com/package/busboy#busboy-methods) for more information on the supported options.
|
|
62
|
-
- `charset` (string) (default `utf-8`): it can be used to change default charset.
|
|
63
|
-
|
|
64
|
-
**Note**: this middleware will buffer all the data as it is processed internally by `busboy`, so, if you are using this approach to parse significantly big volumes of data, keep in mind that all the data will be allocated in memory. This is somewhat inevitable with Lambdas (as the data is already encoded into the JSON in memory as Base64), but it's good to keep this in mind and evaluate the impact on you application.
|
|
65
|
-
If you really have to deal with big files, then you might also want to consider to allowing your users to [directly upload files to S3](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html)
|
|
66
|
-
|
|
67
|
-
## Sample usage
|
|
68
|
-
|
|
69
|
-
```javascript
|
|
70
|
-
import middy from '@middy/core'
|
|
71
|
-
import httpHeaderNormalizer from '@middy/http-header-normalizer'
|
|
72
|
-
import httpMultipartBodyParser from '@middy/http-multipart-body-parser'
|
|
73
|
-
const handler = middy((event, context) => {
|
|
74
|
-
return {}
|
|
75
|
-
})
|
|
76
|
-
handler
|
|
77
|
-
.use(httpHeaderNormalizer())
|
|
78
|
-
.use(httpMultipartBodyParser())
|
|
79
|
-
|
|
80
|
-
// invokes the handler
|
|
81
|
-
const event = {
|
|
82
|
-
headers: {
|
|
83
|
-
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryppsQEwf2BVJeCe0M'
|
|
84
|
-
},
|
|
85
|
-
body: 'LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5cHBzUUV3ZjJCVkplQ2UwTQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJmb28iDQoNCmJhcg0KLS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5cHBzUUV3ZjJCVkplQ2UwTS0t',
|
|
86
|
-
isBase64Encoded: true
|
|
87
|
-
}
|
|
88
|
-
handler(event, {}, (_, body) => {
|
|
89
|
-
t.is(body,{ foo: 'bar' })
|
|
90
|
-
})
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## Middy documentation and examples
|
|
94
|
-
|
|
95
|
-
For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
## Contributing
|
|
99
|
-
|
|
100
|
-
Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
|
|
101
|
-
|
|
102
|
-
|
|
103
39
|
## License
|
|
104
40
|
|
|
105
41
|
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
@@ -107,4 +43,3 @@ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino]
|
|
|
107
43
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
108
44
|
<img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
|
|
109
45
|
</a>
|
|
110
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-multipart-body-parser",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Http event normalizer middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://middy.js.org",
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@middy/util": "4.0.
|
|
65
|
+
"@middy/util": "4.0.2",
|
|
66
66
|
"busboy": "1.6.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@middy/core": "4.0.
|
|
69
|
+
"@middy/core": "4.0.2",
|
|
70
70
|
"@types/aws-lambda": "^8.10.101",
|
|
71
71
|
"type-fest": "^3.0.0"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "c77c9413ecb80999a71b67ff97edac1fed2ca754"
|
|
74
74
|
}
|