On Thursday, July 10, 2014 9:39:09 PM UTC+5:30, Tim Graham wrote: > > It could be useful, however, I think many projects would also want to have > some way of configuring the max file upload size without having to specify > it on every FileField. One way to achieve this might be if a a custom file > upload handler could raise an exception that would be presented as a form > field error which is the original idea from that ticket. >
I found this in tests: class QuotaUploadHandler(FileUploadHandler): """ This test upload handler terminates the connection if more than a quota (5MB) is uploaded. """ QUOTA = 5 * 2 ** 20 # 5 MB def __init__(self, request=None): super(QuotaUploadHandler, self).__init__(request) self.total_upload = 0 def receive_data_chunk(self, raw_data, start): self.total_upload += len(raw_data) if self.total_upload >= self.QUOTA: raise StopUpload(connection_reset=True) return raw_data def file_complete(self, file_size): return None Here, we are using QUOTA, we could also use the setting: FILE_UPLOAD_MAX_MEMORY_SIZE here as well and specify the size in settings file, this does stops the upload but there is no form error. Here is what I have understood: Raising error in uploadhandler to catch in forms might not be possible, because forms are given the data after handlers have done the job eg. form = UploadFileForm(request.POST, request.FILES) But error in handler must have come when `request` was being made. -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6fe70ace-325b-4d21-b080-1b965d86761f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.