{ "info": { "author": "Matt Molyneaux", "author_email": "moggers87+git@moggers87.co.uk", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "=================\nDjango Sendfile 2\n=================\n\n.. image:: https://travis-ci.org/moggers87/django-sendfile2.svg?branch=master\n :target: https://travis-ci.org/moggers87/django-sendfile2\n\nThis is a wrapper around web-server specific methods for sending files to web\nclients. This is useful when Django needs to check permissions associated\nfiles, but does not want to serve the actual bytes of the file itself. i.e. as\nserving large files is not what Django is made for.\n\nNote this should not be used for regular file serving (e.g. css etc), only for\ncases where you need Django to do some work before serving the actual file.\n\nThe interface is a single function `sendfile(request, filename,\nattachment=False, attachment_filename=None)`, which returns a HTTPResponse\nobject.\n\n::\n\n from sendfile import sendfile\n \n # send myfile.pdf to user\n return sendfile(request, '/home/john/myfile.pdf')\n\n # send myfile.pdf as an attachment (with name myfile.pdf)\n return sendfile(request, '/home/john/myfile.pdf', attachment=True)\n \n # send myfile.pdf as an attachment with a different name\n return sendfile(request, '/home/john/myfile.pdf', attachment=True, attachment_filename='full-name.pdf')\n\n\n\nBackends are specified using the setting `SENDFILE_BACKEND`. Currently\navailable backends are:\n\n* `sendfile.backends.development` - for use with django development server\n only. DO NOT USE IN PRODUCTION\n* `sendfile.backends.simple` - \"simple\" backend that uses Django file objects\n to attempt to stream files from disk (note middleware may cause files to be\n loaded fully into memory)\n* `sendfile.backends.xsendfile` - sets X-Sendfile header (as used by\n mod_xsendfile/apache and lighthttpd)\n* `sendfile.backends.mod_wsgi` - sets Location with 200 code to trigger\n internal redirect (daemon mode mod_wsgi only - see below)\n* `sendfile.backends.nginx` - sets X-Accel-Redirect header to trigger internal\n redirect to file\n\nIf you want to write your own backend simply create a module with a `sendfile`\nfunction matching:\n\n::\n\n def sendfile(request, filename):\n '''Return HttpResponse object for serving file'''\n\n\nThen specify the full path to the module in `SENDFILE_BACKEND`. You only need\nto implement the sending of the file. Adding the content-disposition headers\netc is done elsewhere.\n\nSupported Django Versions\n=========================\n\nDjango 1.11, 2.1, and 2.2 are currently supported by this library.\n\nInstallation\n============\n\n::\n\n pip install django-sendfile2\n\nFork\n====\n\nThis project is a fork of `django-sendfile\n`_. The original project\nappears mostly dead and has a number of outstanding bugs (especially with\nPython 3).\n\nDevelopment backend\n===================\n\nThe Development backend is only meant for use while writing code. It uses\nDjango's static file serving code to do the job, which is only meant for\ndevelopment. It reads the whole file into memory and the sends it down the\nwire - not good for big files, but ok when you are just testing things out.\n\nIt will work with the Django dev server and anywhere else you can run Django.\n\nSimple backend\n==============\n\nThis backend is one step up from the development backend. It uses Django's\n`django.core.files.base.File` class to try and stream files from disk. However\nsome middleware (e.g. GzipMiddleware) that rewrites content will causes the\nentire file to be loaded into memory. So only use this backend if you are not\nusing middleware that rewrites content or you only have very small files.\n\n\nxsendfile backend\n=================\n\nInstall either mod_xsendfile_ in Apache_ or use Lighthttpd_. You may need to\nconfigure mod_xsendfile_, but that should be as simple as:\n\n::\n\n XSendFile On\n\nIn your virtualhost file/conf file.\n\n\nmod_wsgi backend\n================\n\nThe mod_wsgi backend will only work when using mod_wsgi in daemon mode, not in\nembedded mode. It requires a bit more work to get it to do the same job as\nxsendfile though. However some may find it easier to setup, as they don't need\nto compile and install mod_xsendfile_.\n\nFirstly there are two more django settings:\n\n* `SENDFILE_ROOT` - this is a directoy where all files that will be used with\n sendfile must be located\n* `SENDFILE_URL` - internal URL prefix for all files served via sendfile\n\nThese settings are needed as this backend makes mod_wsgi_ send an internal\nredirect, so we have to convert a file path into a URL. This means that the\nfiles are visible via Apache_ by default too. So we need to get Apache_ to\nhide those files from anything that's not an internal redirect. To so this we\ncan use some mod_rewrite_ magic along these lines:\n\n::\n\n RewriteEngine On\n # see if we're on an internal redirect or not\n RewriteCond %{THE_REQUEST} ^[\\S]+\\ /private/\n RewriteRule ^/private/ - [F]\n\n Alias /private/ /home/john/Development/myapp/private/\n \n Order deny,allow\n Allow from all\n \n\n\nIn this case I have also set:\n\n::\n\n SENDFILE_ROOT = '/home/john/Development/myapp/private/'\n SENDFILE_URL = '/private'\n\n\nAll files are stored in a folder called 'private'. We forbid access to this\nfolder (`RewriteRule ^/private/ - [F]`) if someone tries to access it directly\n(`RewriteCond %{THE_REQUEST} ^[\\S]+\\ /private/`) by checking the original\nrequest (`THE_REQUEST`).\n\nAllegedly `IS_SUBREQ` can be used to `perform the same job\n`_,\nbut I was unable to get this working.\n\n\nNginx backend\n=============\n\nAs with the mod_wsgi backend you need to set two extra settings:\n\n* `SENDFILE_ROOT` - this is a directory where all files that will be used with\n sendfile must be located\n* `SENDFILE_URL` - internal URL prefix for all files served via sendfile\n\nYou then need to configure nginx to only allow internal access to the files you\nwish to serve. More details on this `are here\n`_.\n\nFor example though, if I use the django settings:\n\n::\n\n SENDFILE_ROOT = '/home/john/Development/django-sendfile/examples/protected_downloads/protected'\n SENDFILE_URL = '/protected'\n\nThen the matching location block in nginx.conf would be:\n\n::\n\n location /protected/ {\n internal;\n root /home/john/Development/django-sendfile/examples/protected_downloads;\n }\n\nYou need to pay attention to whether you have trailing slashes or not on the\nSENDFILE_URL and root values, otherwise you may not get the right URL being\nsent to NGINX and you may get 404s. You should be able to see what file NGINX\nis trying to load in the error.log if this happens. From there it should be\nfairly easy to work out what the right settings are.\n\nFunding\n=======\n\nIf you have found django-sendfile2 to be useful and would like to see its continued\ndevelopment, please consider `buying me a coffee\n`__.\n\n.. _mod_xsendfile: https://tn123.org/mod_xsendfile/\n.. _Apache: http://httpd.apache.org/\n.. _Lighthttpd: http://www.lighttpd.net/\n.. _mod_wsgi: http://www.modwsgi.org/\n.. _mod_rewrite: http://httpd.apache.org/docs/current/mod/mod_rewrite.html", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/moggers87/django-sendfile2", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "django-sendfile2", "package_url": "https://pypi.org/project/django-sendfile2/", "platform": "", "project_url": "https://pypi.org/project/django-sendfile2/", "project_urls": { "Homepage": "https://github.com/moggers87/django-sendfile2" }, "release_url": "https://pypi.org/project/django-sendfile2/0.4.3/", "requires_dist": null, "requires_python": "", "summary": "Abstraction to offload file uploads to web-server (e.g. Apache with mod_xsendfile) once Django has checked permissions etc.", "version": "0.4.3" }, "last_serial": 5930729, "releases": { "0.4.0": [ { "comment_text": "", "digests": { "md5": "2e25160db46c975afc00929533f00d21", "sha256": "ae46ce4362e4f117c8b89c2f31483b37370e9d179ffe70cafe44f2b3282e2d13" }, "downloads": -1, "filename": "django-sendfile2-0.4.0.tar.gz", "has_sig": false, "md5_digest": "2e25160db46c975afc00929533f00d21", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7860, "upload_time": "2018-03-20T17:45:08", "url": "https://files.pythonhosted.org/packages/d3/d9/4c28cc38e72adb9c4a6a5da63c134c1f72aab3254d8f712292a68323fbed/django-sendfile2-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "98c36c6e31d940f02164ca3ca8f5591d", "sha256": "d4729908107efa6d6d9f700985b58677c072dcd3e76e3d20ff614ee269f30607" }, "downloads": -1, "filename": "django-sendfile2-0.4.1.tar.gz", "has_sig": false, "md5_digest": "98c36c6e31d940f02164ca3ca8f5591d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8304, "upload_time": "2018-03-21T01:06:09", "url": "https://files.pythonhosted.org/packages/ca/4e/541cd15456450b8d0f715399029b70ca116fd75a21191dd65f7619373066/django-sendfile2-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "231bd8aebb107231e0a56d0bc55a7191", "sha256": "b1654d844d68da45620bc27eda3c4b89c2cbbd521146f88a05f3347375807757" }, "downloads": -1, "filename": "django-sendfile2-0.4.2.tar.gz", "has_sig": false, "md5_digest": "231bd8aebb107231e0a56d0bc55a7191", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27159, "upload_time": "2018-09-19T09:29:32", "url": "https://files.pythonhosted.org/packages/b1/e5/86624c566758d09d3552eb29bddd6d120bb416efdc311ae79c6dc47ef257/django-sendfile2-0.4.2.tar.gz" } ], "0.4.3": [ { "comment_text": "", "digests": { "md5": "135f2abe01facd8abbafe459a93dc69e", "sha256": "267cdd817a5fe7e649df9139ac3efbe8675c61ccdab43146d1e8cbd9bab70554" }, "downloads": -1, "filename": "django-sendfile2-0.4.3.tar.gz", "has_sig": false, "md5_digest": "135f2abe01facd8abbafe459a93dc69e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24399, "upload_time": "2019-10-05T00:20:47", "url": "https://files.pythonhosted.org/packages/3d/f9/494ff1c182051a065a11c5ee24c14ea6b12b350a17e4dad021f5c0477532/django-sendfile2-0.4.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "135f2abe01facd8abbafe459a93dc69e", "sha256": "267cdd817a5fe7e649df9139ac3efbe8675c61ccdab43146d1e8cbd9bab70554" }, "downloads": -1, "filename": "django-sendfile2-0.4.3.tar.gz", "has_sig": false, "md5_digest": "135f2abe01facd8abbafe459a93dc69e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24399, "upload_time": "2019-10-05T00:20:47", "url": "https://files.pythonhosted.org/packages/3d/f9/494ff1c182051a065a11c5ee24c14ea6b12b350a17e4dad021f5c0477532/django-sendfile2-0.4.3.tar.gz" } ] }