From f60ec3358318b6428cdf31372cce392251a11210 Mon Sep 17 00:00:00 2001 From: Christopher Stoll Date: Wed, 6 May 2020 15:45:16 -0400 Subject: [PATCH 1/2] Fix docker build issues on MacOS Catalina --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 9cd6dc9..7ff2521 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ RUN apt-get update && apt-get install -y \ COPY requirements.txt /app/ RUN pip install --upgrade pip \ + && pip install --no-cache-dir llvmlite==0.31.0 \ && pip install --no-cache-dir -r requirements.txt \ && pip install --no-cache-dir gunicorn psycopg2-binary From 024e0d0f81ca3233c6376d1278805ef427a3f117 Mon Sep 17 00:00:00 2001 From: Christopher Stoll Date: Wed, 6 May 2020 15:47:54 -0400 Subject: [PATCH 2/2] Fix for downloading large image zips (stream them) --- annotator/views.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/annotator/views.py b/annotator/views.py index da52c73..096f535 100644 --- a/annotator/views.py +++ b/annotator/views.py @@ -3,6 +3,8 @@ import logging import subprocess import re +import os +import mimetypes #import cv2 #import numpy as np from django.shortcuts import render @@ -12,7 +14,8 @@ from django.views.decorators.cache import never_cache from django.db import IntegrityError from django.db.models import Max -from django.http import JsonResponse +from django.http import JsonResponse, StreamingHttpResponse +from wsgiref.util import FileWrapper from celery.result import AsyncResult from celery import chain from celery import states as task_states @@ -709,13 +712,12 @@ class ExportVideo(View): def get(self, request, vid): video = Video.objects.get(id=vid) if video.zipfile and os.path.exists(video.zipfile.path): - with open(video.zipfile.path, 'rb') as f: - response = HttpResponse( - f, content_type='application/x-zip-compressed') - response['Content-Disposition'] = ( - 'attachment; ' - 'filename={}.zip' - ).format(video.name) + chunk_size = 8192 + filename = os.path.basename(video.zipfile.path) + response = StreamingHttpResponse(FileWrapper(open(video.zipfile.path, 'rb'), chunk_size), + content_type=mimetypes.guess_type(video.zipfile.path)[0]) + response['Content-Length'] = os.path.getsize(video.zipfile.path) + response['Content-Disposition'] = "attachment; filename=%s" % filename else: response = HttpResponseNotFound('File does not exist') return response