def post_file() -> JSONResponse[str]:
"""Temporarily store some data on the server.
.. :quickref: File; Safe a file temporarily on the server.
.. note::
The posted data will be removed after 60 seconds.
:returns: A response with the JSON serialized name of the file as content
and return code 201.
:raises APIException: If the request is bigger than the maximum upload
size. (REQUEST_TOO_LARGE)
:raises PermissionException: If there is no logged in user. (NOT_LOGGED_IN)
"""
if (
request.content_length and
request.content_length > app.config['MAX_UPLOAD_SIZE']):
raise APIException(
'Uploaded file is too big.',
'Request is bigger than maximum upload size of {}.'.format(
app.config['MAX_UPLOAD_SIZE']
), APICodes.REQUEST_TOO_LARGE, 400
)
path, name = psef.files.random_file_path('MIRROR_UPLOAD_DIR')
FileStorage(request.stream).save(path)
return jsonify(name, status_code=201)
评论列表
文章目录