Use the content_length to signal whether or not this handler should be used.
(
self, input_data, META, content_length, boundary, encoding=None
)
| 197 | """ |
| 198 | |
| 199 | def handle_raw_input( |
| 200 | self, input_data, META, content_length, boundary, encoding=None |
| 201 | ): |
| 202 | """ |
| 203 | Use the content_length to signal whether or not this handler should be |
| 204 | used. |
| 205 | """ |
| 206 | # If the post is too large, we cannot use the Memory handler. |
| 207 | # Content-Length can be absent or understated (for example |
| 208 | # `Transfer-Encoding: chunked` on ASGI), so for seekable streams (such |
| 209 | # as SpooledTemporaryFile on ASGI), check the actual size. |
| 210 | |
| 211 | stream = getattr(input_data, "_stream", input_data) |
| 212 | try: |
| 213 | content_length = stream.seek(0, os.SEEK_END) |
| 214 | except (UnsupportedOperation, AttributeError): |
| 215 | # Cannot seek; fall back to the Content-Length parameter. |
| 216 | # On WSGI the stream enforces this value so it is trustworthy. |
| 217 | pass |
| 218 | else: |
| 219 | stream.seek(0) |
| 220 | self.activated = ( |
| 221 | content_length is not None |
| 222 | and content_length <= settings.FILE_UPLOAD_MAX_MEMORY_SIZE |
| 223 | ) |
| 224 | |
| 225 | def new_file(self, *args, **kwargs): |
| 226 | super().new_file(*args, **kwargs) |