Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set an uploaded file size limit in tornado?

I am using tornado to make an image processing RESTful service, which is accepting images uploaded by general HTTP means like multipart/form-data. I then access them in handlers using self.request.files.

It could be that an adversary will try to upload a huge file to break down a service. Is there any way to tell tornado an uploaded file size limit, exceeding which file should be discarded and error HTTP status should be set?

like image 318
bazzilic Avatar asked Oct 05 '12 12:10

bazzilic


People also ask

How do I change max upload file size?

Open the file in any text editor and add the following code. @ini_set( 'upload_max_size' , '20M' ); @ini_set( 'post_max_size', '13M'); @ini_set( 'memory_limit', '15M' ); Save your changes, and it should increase your file upload size.

What is the maximum file uploading limit?

Uploading large files to a server consumes a lot of the server's resources. To prevent users from causing server timeouts, the default maximum upload size in WordPress typically ranges from 4 MB to 128 MB.

What is the maximum file size for uploads in a browser?

What is the maximum file size for uploads in a browser? Internet Explorer v9 - v11, Chrome, Safari, Edge, and Firefox support the HTML5 uploader, which has a max 4GB file size limit. Both Chrome and Edge support folder uploads.


1 Answers

I've tried this, It works! max_buffer_size default value is 100 M.

import tornado.httpserver

app = tornado.web.Application([
    (r'/upload/', UploadFileHandler),
])

server = tornado.httpserver.HTTPServer(app, max_buffer_size=10485760000)  # 10G
server.listen(8888)
tornado.ioloop.IOLoop.instance().start()
like image 106
WeizhongTu Avatar answered Oct 05 '22 18:10

WeizhongTu