djangosnippets.org: Latest snippets tagged with 'sendfile'https://djangosnippets.org/tags/sendfile/2019-04-17T06:53:36.356646-05:00Django nginx sendfile example
2019-04-17T06:53:36.356646-05:00sim1234https://djangosnippets.org/snippets/10664/<p>Use nginx sendfile (X-Accel-Redirect) function to serve files but pass traffic through django. Can be used to serve media files only to logged-in users.</p>
Freely redistributableHttpResponseSendfile
2012-05-02T19:58:39.531445-05:00eternicodehttps://djangosnippets.org/snippets/2739/<p>An HttpResponse for giving the user a file download, taking advantage of X-Sendfile if it's available, using FileWrapper if not.</p>
<p>Usage:</p>
<pre><code>HttpResponseSendfile('/path/to/file.ext')
</code></pre>
<p>To bypass the fallback:</p>
<pre><code>HttpResponseSendfile('/path/to/file.ext', fallback=False)
</code></pre>
<p>This has been tested working with Lighttpd 1.4.28's mod_fastcgi.</p>
Freely redistributableSend large files through Django, and how to generate Zip files
2007-08-12T17:56:44.181568-05:00jcrochollhttps://djangosnippets.org/snippets/365/<p>This snippet demonstrates how you can send a file (or file-like object) through Django without having to load the whole thing into memory. The FileWrapper will turn the file-like object into an iterator for chunks of 8KB.</p>
<p>This is a full working example. Start a new app, save this snippet …</p>
Freely redistributable