2
Upload handlers to test the upload API.
5
from django.core.files.uploadhandler import FileUploadHandler, StopUpload
7
class QuotaUploadHandler(FileUploadHandler):
9
This test upload handler terminates the connection if more than a quota
13
QUOTA = 5 * 2**20 # 5 MB
15
def __init__(self, request=None):
16
super(QuotaUploadHandler, self).__init__(request)
19
def receive_data_chunk(self, raw_data, start):
20
self.total_upload += len(raw_data)
21
if self.total_upload >= self.QUOTA:
22
raise StopUpload(connection_reset=True)
25
def file_complete(self, file_size):
28
class CustomUploadError(Exception):
31
class ErroringUploadHandler(FileUploadHandler):
32
"""A handler that raises an exception."""
33
def receive_data_chunk(self, raw_data, start):
34
raise CustomUploadError("Oops!")