The `multipart` library (v1.3.1) provides a robust parser for `multipart/form-data` requests, commonly used in web applications for handling file uploads and complex form submissions. It supports both synchronous and asynchronous parsing, making it suitable for various web frameworks. The project is actively maintained with periodic security updates.
pip install multipartVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to parse a `multipart/form-data` request body using `multipart.parse_form`. It simulates an HTTP request by creating an `io.BytesIO` object for the body and specifying `Content-Type` and `Content-Length` headers. The parsed data is returned as `form` (text fields) and `files` (file fields), which are then iterated over.
To resolve an `ImportError`, ensure you are importing `parse_form` from the correct location for your specific `multipart` version (e.g., `from multipart.foo import parse_form_old_name`), or consider upgrading to `multipart` version 1.0.0 or higher. If upgrading, update your call to `parse_form` to explicitly pass the input stream, content type, and content length: `form, files = parse_form(input_stream, content_type_header, content_length_header)`.
Upgrade to `multipart` version 1.3.1 or higher immediately to patch this critical security vulnerability. If you are on an older 1.x release, upgrade to the latest patch version available.
Always call `file_item.file.close()` after you are done reading from or processing the file content for each `file_item`.
No dependency data recorded yet.