MAX_UPLOAD_SIZE = 5 * 1024 * 1024
MAX_CONTENT_LENGTH = 16 * 1024 * 1024
class UploadImages(FlaskForm):
images = MultipleFileField('Upload images', validators=[Required()])
submit = SubmitField('Upload')
def validate_images(self, images):
for file in images.data:
# File extension check
extension = file.filename.lower().split('.')[-1]
if extension not in images.extensions:
raise ValidationError('Images only!')
# File size check
file.seek(0, 2)
file_size = file.tell()
file.seek(0)
if file_size > current_app.config['MAX_UPLOAD_SIZE']:
raise ValidationError('5 Mb maximum!')