Closed introprog-dc closed 11 months ago
Hi @introprog-dc! This is by design -- in the same way as you cannot read from a stream twice (unless it is seekable).
Iterating over a multipart form consumes the request stream, and no, you cannot iterate twice.
Maybe you could potentially redesign your application so that it doesn't need to iterate twice, and handle the form on-the-fly, or at least its file parts? Other small fields you can buffer in a dict
.
Hi @vytas7! Thanks for your quick reply. I will try to implement a different approach then.
I'm building a simple web app that receives a form with an attached file. I'm also using a logger middleware to store a log of each request, thus I want to log the content of the file as well. However, it seems the
MultipartForm
object gets consumed on theon_post()
method and when the logger middleware tries to access it, it breaks.Things I've tried:
copy.deepcopy()
to clone the MultipartForm object so it gets not destroyed -> it breaks withTypeError: no default __reduce__ due to non-trivial __cinit__
The behavior can be easily reproduced iterating twice:
It only prints results for the first loop:
Thanks in advance for any help you can provide. I really like falcon :)