Search code examples
pythondjangoapipython-requestssanic

How to increase timeout while uploading on the Sanic framework?


I have a method in Sanic for uploading files. Sometimes my file size is large or the connection between server and clients is poor So, in this situation I lose my request because the clients occur with a timeout exception. I want to increase timeout on top of a specific method.

# I want to define set timeout period here
# @set_imeout(4 * 60)
@song.route('/upload', methods=["POST"])
@is_authenticated()
@required_roles(['cafe'])
@jsonify
async def process_upload(request):
    # upload method
    do something for upload

Solution

  • As of Sanic 20.3 this is not possible but such functionality is planned in a future release.

    https://github.com/huge-success/sanic/pull/1791 allows adjusting request maximum size in streaming handlers, and also resets the request timeout whenever there is I/O, so that lengthy uploads should not timeout.