--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think a streaming multipart/form-data parser would be useful, but it's not obvious what the right interface is. Writing everything to disk to be read later (as you've done) is one good approach, but I deliberately avoided any direct disk access in the @stream_request_body interface so that applications could e.g. pass an uploaded file directly into s3 without touching local disk (and enforce appropriate flow control). I think any interface built in to Tornado itself should have similar properties to the existing @stream_request_body, even if there is a higher-level alternative to buffer everything on disk.
There should be a way to set a default max_buffer_size for the server globally, and increase max_buffer_size for individual request handlers.
Is it possible?
- if we limit max_buffer_size and max_body_size, then large files cannot be posted to the server
- if we set max_buffer_size and max_body_size to a large value, then huge files can be posted to the server, and it is not possible to prevent posting large amounts of data and force the server to load it into memory
There should be a way to set a default max_buffer_size for the server globally, and increase max_buffer_size for individual request handlers.
Is it possible?
I can see that max_buffer_size is passed to TCPServer and max_body_size is passed to HTTP1ConnectionParameters. I guess there is no way to set a different max_buffer_size for request handlers, because there is a single TCPServer that accepts the incoming requests. When tornado decides which request handler is to be used, HTTP1ConnectionParameters was already used to determine the parameters, right?
Suggestion: Normally, RequestHandler.prepare is called when the entire request body is available. If the stream_request_body decorator is given, then prepare is called when request headers are available. In order to limit the max body size for request handlers individually, we should have a base method in HTTPRequest that is called when request headers are available, even if the request handler was not decorated with stream_request_body. In that base method, it should be possible to set a maximum request size. The server should terminate the connection if Content-Length is higher than the maximum allowed, and also when the size of the (partly) loaded request exceeeds the given limit.
We already have an API like this, although it was omitted from the documentation. `self.request.connection.set_max_body_size()` may be called in `prepare()` and works as you describe:This way you can set max_buffer_size and the default max_body_size to relatively small values (the size of the largest body you will accept without @stream_request_body), then increase max_body_size in prepare() for those handlers that accept larger files (and because it's streaming, you don't need to change max_buffer_size).
--
You received this message because you are subscribed to a topic in the Google Groups "Tornado Web Server" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-tornado/izEXQd71rQk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-tornado+unsubscribe@googlegroups.com.
IOLoop.
spawn_callback
(callback, *args, **kwargs), does it mean that we use another ioloop to run the client?could you explain for me?ok,thanks a lot.waiting for your module of the on-the-fly conversion as soon as possible.Actually,I have read the code(https://gist.github.com/bdarnell/5bb1bd04a443c4e06ccd) on github,and I am a little confused.Does it mean that all the server and client are fulfilled in the same streaming.py file?
Shouldn't they be separated?
class UploadHandler and class ProxyHandler are the request handler of server,but I don't really understand what does def client mean,I have checked the API document ofIOLoop.
spawn_callback
(callback, *args, **kwargs), does it mean that we use another ioloop to run the client?could you explain for me?
It is scheduled in the "current" ioloop. In the streaming.py example, there is a single ioloop. In most async applications, there is a single loop. Spawn_callback does not create a loop.
Hi,I have tried to run this example,and I am a little confused by some statements:1.logging.info('ProxyHandler.data_received(%d bytes: %r)',len(chunk), chunk[:9])what does chunk[:9]mean?is it a regular expression?
2.also ,I can't make sure what does chunk = ('chunk %02d ' % i) * 10000 mean?
def prepare(self): max_buffer_size = 4 * 1024**3 # 4GB self.request.connection.set_max_body_size(max_buffer_size) self.temp_file = open("test.txt","w") def data_received(self, chunk): self.temp_file.write(chunk)
With the above code I am able to upload file but in raw data form as shown below
-----------------------------6552719992117258671800152707 Content-Disposition: form-data; name="dest"
csv -----------------------------6552719992117258671800152707 Content-Disposition: form-data; name="carrier"
bandwidth -----------------------------6552719992117258671800152707 Content-Disposition: form-data; name="file1"; filename="test.csv" Content-Type: text/csv
And the content of uploaded file follows here.
How do I get the request parameters parsed from the file and separate the data of the file uploaded? Is there any other way to upload large files(around 2 GB) in tornado
@stream_request_body class StreamHandler(RequestHandler): def post(self): self.temp_file.close()
def prepare(self):
max_buffer_size = 4 * 1024**3 # 4GB
self.request.connection.set_max_body_size(max_buffer_size)
self.temp_file = open("test.txt","w")
def data_received(self, chunk):
self.temp_file.write(chunk)
With the above code I am able to upload file but in raw data form as shown below
-----------------------------6552719992117258671800152707 Content-Disposition: form-data; name="dest"
csv -----------------------------6552719992117258671800152707 Content-Disposition: form-data; name="carrier"
bandwidth -----------------------------6552719992117258671800152707 Content-Disposition: form-data; name="file1"; filename="test.csv" Content-Type: text/csv
And the content of uploaded file follows here.
How do I get the request parameters parsed from the file and separate the data of the file uploaded? Is there any other way to upload large files(around 2 GB) in tornado
--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-tornado/a9ad91f6-c51b-4e66-96c0-7b00cf94a597%40googlegroups.com.
@stream_request_bodyclass StreamHandler(RequestHandler):def post(self):self.temp_file.close()def prepare(self): max_buffer_size = 4 * 1024**3 # 4GB self.request.connection.set_max_body_size(max_buffer_size) self.temp_file = open("test.txt","w") def data_received(self, chunk): self.temp_file.write(chunk)
With the above code I am able to upload file but in raw data form as shown below
-----------------------------6552719992117258671800152707 Content-Disposition: form-data; name="dest"
csv -----------------------------6552719992117258671800152707 Content-Disposition: form-data; name="carrier"
bandwidth -----------------------------6552719992117258671800152707 Content-Disposition: form-data; name="file1"; filename="test.csv" Content-Type: text/csv
And the content of uploaded file follows here.
How do I get the request parameters parsed from the file and separate the data of the file uploaded? Is there any other way to upload large files(around 2 GB) in tornado
This is the multipart protocol used by HTML forms. Tornado can currently only parse this if it sees all the data at once, not in a streaming upload. There's a third-party library that should be able to handle this: https://github.com/siddhantgoel/streaming-form-data. See this issue for more: https://github.com/tornadoweb/tornado/issues/1842