Created
January 10, 2022 19:59
-
-
Save sphaugh/bba68b41faf0e8db0ab8d226dea0be0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from base64 import b64decode | |
from functools import wraps | |
from io import BytesIO, StringIO | |
from werkzeug.datastructures import Headers | |
from werkzeug.formparser import parse_form_data | |
def use_form(func): | |
@wraps(func) | |
def func_with_form_data(event, *args, **kwargs): | |
body = b64decode(event["body"]) if event["isBase64Encoded"] else event["body"] | |
event["headers"] = Headers(event["headers"]) | |
environ = { | |
"wsgi.input": BytesIO(body) if isinstance(body, bytes) else StringIO(body), | |
"CONTENT_LENGTH": len(body), | |
"CONTENT_TYPE": event["headers"]["Content-Type"], | |
"REQUEST_METHOD": "POST", | |
} | |
_, event["form"], event["files"] = parse_form_data(environ) | |
return func(event, *args, **kwargs) | |
return func_with_form_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment