On Tue, Aug 16, 2011 at 3:58 PM, sebastiaan <svanachterbe...@gmail.com> wrote:
> Hi,
>
> currently I'm working on an application that serves PDF files using
> HttpResponse:
>
>        f = open( pdfFileName, 'r' )
>
>        response = http.HttpResponse( f.read(), mimetype='application/
> pdf' )
>        response['Content-Disposition'] = 'attachment; filename=%s' %
> pdfFileName
>
>        f.close()
>
>        return response
>
> Problem is that HttpResponse creates the served file in /tmp which is
> not desirable.
>
> Anyone have a suggestion?
>
> PS: I've also tried with StringIO, same result.
>

I wasn't aware django buffered responses into TMPDIR, however...

HttpResponse either takes a string or a file-like object. When you
pass it a file-like object it reads it in chunks and outputs it in
chunks. You're passing it a string, but you could just pass it the
file handle, in which case it would output it in chunks*.

Cheers

Tom

* Certain middleware breaks with chunked style responses, particularly
caching. See [1] for details.

[1] https://code.djangoproject.com/ticket/6527

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to