def get_file(
file_name: str, name: str = 'export'
) -> werkzeug.wrappers.Response:
"""Serve some specific file in the uploads folder.
.. :quickref: File; Get an uploaded file directory.
.. note::
Only files uploaded using :http:post:`/api/v1/files/` may be retrieved.
:param str file_name: The filename of the file to get.
:returns: The requested file.
:raises PermissionException: If there is no logged in user. (NOT_LOGGED_IN)
"""
name = request.args.get('name', name)
directory = app.config['MIRROR_UPLOAD_DIR']
error = False
@after_this_request
def delete_file(response: t.Any) -> t.Any:
if not error:
filename = safe_join(directory, file_name)
os.unlink(filename)
return response
try:
mimetype = request.args.get('mime', None)
as_attachment = request.args.get('not_as_attachment', False)
return send_from_directory(
directory,
file_name,
attachment_filename=name,
as_attachment=as_attachment,
mimetype=mimetype
)
except NotFound:
error = True
raise APIException(
'The specified file was not found',
f'The file with name "{file_name}" was not found or is deleted.',
APICodes.OBJECT_NOT_FOUND,
404,
)
评论列表
文章目录