def save(self, storage, folder=None, name=None):
if not isinstance(storage, FileStorage):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if folder is None and name is not None and "<STR_LIT:/>" in name:<EOL><INDENT>folder, name = os.path.split(name)<EOL><DEDENT>basename = self.get_basename(storage.filename)<EOL>if name:<EOL><INDENT>if name.endswith('<STR_LIT:.>'):<EOL><INDENT>basename = name + extension(basename)<EOL><DEDENT>else:<EOL><INDENT>basename = name<EOL><DEDENT><DEDENT>if not self.file_allowed(storage, basename):<EOL><INDENT>raise UploadNotAllowed()<EOL><DEDENT>if folder:<EOL><INDENT>target_folder = os.path.join(self.config.destination, folder)<EOL><DEDENT>else:<EOL><INDENT>target_folder = self.config.destination<EOL><DEDENT>if not os.path.exists(target_folder):<EOL><INDENT>os.makedirs(target_folder)<EOL><DEDENT>if os.path.exists(os.path.join(target_folder, basename)):<EOL><INDENT>basename = self.resolve_conflict(target_folder, basename)<EOL><DEDENT>target = os.path.join(target_folder, basename)<EOL>storage.save(target)<EOL>if folder:<EOL><INDENT>return posixpath.join(folder, basename)<EOL><DEDENT>else:<EOL><INDENT>return basename<EOL><DEDENT>
This saves a `werkzeug.FileStorage` into this upload set. If the
upload is not allowed, an `UploadNotAllowed` error will be raised.
Otherwise, the file will be saved and its name (including the folder)
will be returned.

:param storage: The uploaded file to save.
:param folder: The subfolder within the upload set to save to.
:param name: The name to save the file as. If it ends with a dot, the
             file's extension will be appended to the end. (If you
             are using `name`, you can include the folder in the
             `name` instead of explicitly using `folder`, i.e.
             ``uset.save(file, name="someguy/photo_123.")``