On Sep 14, 2017 3:48 PM, <pieceofkayk2...@gmail.com> wrote: Hey guys,
I'm trying to make a view so that my users can download a compressed tar archive. I've seen a ton of examples about downloading files yet cannot seem to find anything regarding tar. Anyone want to drop me an awesome example? for a simple file I have def download_file(request, pk): my_model = SomeModel.objects.get(pk=pk) file_path = my_model.get_file_path() if os.path.exists(file_path): with open(file_path, 'rb') as fh: response = HttpResponse(fh.read(), content_type="") response['Content-Disposition'] = 'inline; filename=' + os.path. basename(file_path) return reponse There isn't anything special about serving different types of files. The only trick is to specify the correct MIME type if you know it (which you do in this case, application/x-tar). Then it's just a matter of using inline or attachment (recommended) for the content disposition header. https://docs.djangoproject.com/en/1.11/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment https://docs.djangoproject.com/en/1.11/howto/outputting-csv/#using-the-python-csv-library Or better yet, hand the file transfer off to the web server process, where it belongs. http://voorloopnul.com/blog/serving-large-and-small-files-with-django/ -James -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciX%2B-rXTGiqdtifzJX5e%3DdEHE8YF%2BVnYyZd3H9%2BgDhL3uA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.