> What is 'wsgi.file_wrapper' anyway?

It's a WSGI hook defined in PEP 333 and 3333 
(https://www.python.org/dev/peps/pep-3333/#optional-platform-specific-file-handling)

It basically lets your application defer to an iterator defined in 
middleware file responses.  In the Pyramid code, you'll see that it checks 
to see if there is a middleware filewrapper, and falls back to Pyramid's 
option.

If you have loaded the bytes, you can use a BytesIO object, which is 
in-memory. 

If the file might be large, you could write the data to tempfile.
SpooledTemporaryFile -- which will be in-memory until it hits a max-size, 
and then writes to disk.  


On Saturday, October 17, 2020 at 3:07:13 AM UTC-4 Mike Orr wrote:

> I'm migrating user-uploaded files from a local filesystem to MinIO (an
> S3-compatible file server). I can't use FileResponse because I get
> back a filehandle or a bytes, and I'd have to write it to a temporary
> file to use FileResponse.I'm also exploring presigned URLs to have the
> browser fetch the file, but right now I want to serve it server-side.
> What Pyramid response args should I use, and how should I stream the
> content? I looked at the source of FileResponse, and it creates an
> 'app_iter' object using 'environ["wsgi.file_wrapper"]'. Do I have to
> do all that? Or can I just do 'body_file=result["body"]', which is the
> filehandle and has a 'read' method. What is 'wsgi.file_wrapper'
> anyway?
>
> -- 
> Mike Orr <slugg...@gmail.com>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/39ecc9ad-23b3-4541-a4c3-a4d4b52973c7n%40googlegroups.com.

Reply via email to