Comments (4)
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.
@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.
gunicorn also provides this extensions, and the default django server will block gevent threads when it serves the file
from django-sendfile.
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)
- mod_wsgi backend broken on Django 1.8 HOT 9
- Our abc.tar.gz file sent using this django-sendfile was automatically getting unzipped by the browser
- Release 0.3.8 HOT 2
- Licensing HOT 4
- Problem with unicode characters HOT 10
- PyPi page looks strange HOT 2
- Is status really "Beta"? HOT 5
- Content-Disposition: Output contains buffer repr (Python 3.4) HOT 1
- Django 1.9 support HOT 4
- How to make "private" media accessible by site staff? HOT 1
- Add tests running in CI
- Support wheel packaging
- Serve a folder with sendfile
- Simple backend will decompress file HOT 1
- Maintaining the project HOT 12
- Apache 2.4 EnableSendfile as a potential replacement for XSendfile HOT 3
- I have to append `media/` to the path to not get a 404
- How to override the image url / path?
- Django 2.1 and above has removed the permalink() decorator HOT 1
- Please redirect to django-sendfile2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-sendfile.