Browse Source

Other way of stream images to client

Felix Schultze 9 years ago
parent
commit
432690cbf9
1 changed files with 10 additions and 1 deletions
  1. 10 1
      volumes/views.py

+ 10 - 1
volumes/views.py

@@ -1,8 +1,9 @@
 from django.core.urlresolvers import reverse
 from django.shortcuts import render, render_to_response
 from django.template import RequestContext
-from django.http import HttpResponseRedirect, HttpResponse
+from django.http import HttpResponseRedirect, HttpResponse, StreamingHttpResponse
 from django.contrib import messages
+from django.core.servers.basehttp import FileWrapper
 
 from django.conf import settings
 
@@ -158,10 +159,18 @@ def showSprite(request, id, spriteId):
     if contenttype is None:
         contenttype = 'image/jpeg'
 
+    chunk_size = 8192
+    response = StreamingHttpResponse(FileWrapper(sprite, chunk_size),
+                                     content_type=contenttype)
+    response['Content-Length'] = sprite.length
+    response['Content-Disposition'] = "attachment; filename=%s" % sprite._id
+    return response
+    '''
     response = HttpResponse(sprite.read(), content_type=contenttype)
     response['Content-Length'] = sprite.length
 
     return response
+    '''
 
 
 def getTextureInfo(request, id, size):