Giter Club home page Giter Club logo

Comments (4)

johnsensible avatar johnsensible commented on August 20, 2024

Hmmm. I'm not quite sure. The app only returns a Django response
object, so not sure how you'd pass the FileWrapper to WSGI.

Some testing would be needed.

You can easily write your own backend. Just create a module with a
single method:

def sendfile(request, filename, **kwargs)

Then set SENDFILE_BACKEND to the dotted name of your module (e.g.
"mypackage.mymodule").

It might be as simple as something like:

def sendfile(request, filename, **kwargs):
return environ['wsgi.file_wrapper'](open(filename), block_size)

Just not sure whether Django will get confused. Might be you have to
patch in extra things to the file wrapper object to keep Django happy.

Probably best to give it a go and see.

On Fri, 2012-06-08 at 03:19 -0700, André Cruz wrote:

The WSGI protocol specifies an optional mechanism for higher performance file transmission.

There is at least one wsgi server that implements this: uWSGI.

A backend that takes advantage of this mechanism would be very interesting. Is it possible to write one using the current API?


Reply to this email directly or view it on GitHub:
#6

from django-sendfile.

graingert avatar graingert commented on August 20, 2024

@johnsensible the sendfile method doesn't have access to the environ dict, and nor does django support returning anything other that django HttpResponse(s)

from django-sendfile.

graingert avatar graingert commented on August 20, 2024

gunicorn also provides this extensions, and the default django server will block gevent threads when it serves the file

from django-sendfile.

kezabelle avatar kezabelle commented on August 20, 2024

Dredging this up from years ago to document its possibility now.
As of Django 1.8 (LTS), there is a new HttpResponse class called FileResponse (see ticket 24072) which does allow for a Django Response to populate the wsgi.file_wrapper (see commits 3d2cae0896ee8026d1c2c5d31e4c4c8f74f2fef4 and a9aec1154e5b65fcaf608801905a1bbafcfbfbf7)

I believe the implementation would probably simply be:

def sendfile(request, filename, **kwargs):
    return FileResponse(open(filename))

block size is a class attribute on FileResponse so doesn't need to be passed along (indeed I'm not sure it can be)
Django will handle closing the object when the response finishes, if appropriate.

from django-sendfile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.