def save_file(self, data, filename, size=None, thumbnail_size=None):
max_size = size or self.max_size<EOL>thumbnail_size = thumbnail_size or self.thumbnail_size<EOL>if data and isinstance(data, FileStorage):<EOL><INDENT>try:<EOL><INDENT>self.image = Image.open(data)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValidationError("<STR_LIT>" % e)<EOL><DEDENT><DEDENT>path = self.get_path(filename)<EOL>if not op.exists(op.dirname(path)):<EOL><INDENT>os.makedirs(os.path.dirname(path), self.permission)<EOL><DEDENT>filename, format = self.get_save_format(filename, self.image)<EOL>if self.image and (self.image.format != format or max_size):<EOL><INDENT>if max_size:<EOL><INDENT>image = self.resize(self.image, max_size)<EOL><DEDENT>else:<EOL><INDENT>image = self.image<EOL><DEDENT>self.save_image(image, self.get_path(filename), format)<EOL><DEDENT>else:<EOL><INDENT>data.seek(<NUM_LIT:0>)<EOL>data.save(path)<EOL><DEDENT>self.save_thumbnail(data, filename, format, thumbnail_size)<EOL>return filename<EOL>
Saves an image File

:param data: FileStorage from Flask form upload field
:param filename: Filename with full path