Beispiel #1
0
    def get(self, request, *args, **kwargs):
        error_response = self.check_before_zipping()
        if error_response:
            return error_response

        path = None
        transfer_enabled = settings.SHARED_DRIVE_CONF.transfer_enabled
        if transfer_enabled:
            path = os.path.join(settings.SHARED_DRIVE_CONF.transfer_dir,
                                uuid.uuid4().hex)

        files, errors = self.iter_files()
        fpath = make_zip_file(files, compress=self.compress_zip, path=path)
        if errors:
            self.log_errors(errors)

        if transfer_enabled:
            return TransferHttpResponse(fpath, content_type=self.zip_mimetype)
        else:
            response = StreamingHttpResponse(FileWrapper(
                open(fpath), CHUNK_SIZE),
                                             content_type=self.zip_mimetype)
            response['Content-Length'] = os.path.getsize(fpath)
            set_file_download(response, self.zip_name)
            return response
Beispiel #2
0
    def toHttpResponse(self):
        if self.use_transfer:
            response = TransferHttpResponse(self.filename,
                    content_type=self.content_type)
        else:
            response = StreamingHttpResponse(FileWrapper(open(self.filename), CHUNK_SIZE),
                                             content_type=self.content_type)

        response['Content-Length'] = os.path.getsize(self.filename)
        response['Content-Disposition'] = self.content_disposition
        if self.transfer_encoding is not None:
            response['Transfer-Encoding'] = self.transfer_encoding
        for k, v in self.extras.items():
            response[k] = v
        return response
Beispiel #3
0
def download(request):
    return TransferHttpResponse(make_tempfile())