Hey guys, I'm using the Maverick packages, so Django 1.2.3
I need to serve a large binary (an mp3 in this case) directly through Django to ensure good access control independent of the web server itself.
I have the following snippet of code, to download binary files via django:
filename = os.path.join(settings.MEDIA_ROOT, diary.file.name) filesize = os.path.getsize(filename) mimetype, encoding = mimetypes.guess_type(filename) lastmodified = http_date(os.path.getmtime(filename)) wrapper = FileWrapper(file(filename)) response = HttpResponse(wrapper, content_type=mimetype) #response = HttpResponse(open(filename).read(), content_type=mimetype) response['Content-Length'] = filesize response['Last-Modified'] = lastmodified return response
For some reason, I only ever get a zero-length response out of this. But if I uncomment the other HttpResponse, the one that reads it all into memory first (yuck!) it works just fine. Why would the FileWrapper not be doing what it's supposed to do?
-- 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.