This question already has answers here:
Python bottle - How to upload media files without DOSing the server
(2个答案)
4年前关闭。
如何限制用户能够上传到我的服务器的文件大小?
我正在使用瓶子0.12和python 3.4。
Python bottle - How to upload media files without DOSing the server
(2个答案)
4年前关闭。
如何限制用户能够上传到我的服务器的文件大小?
我正在使用瓶子0.12和python 3.4。
最佳答案
MAX_SIZE = 5 * 1024 * 1024
BUF_SIZE = 8192
data_blocks = []
byte_count = 0
buf = f.read(BUF_SIZE)
while buf:
byte_count += len(buf)
if byte_count > MAX_SIZE:
# if you want to just truncate at (approximately) MAX_SIZE bytes:
break
# or, if you want to abort the call
raise bottle.HTTPError(413, 'Request entity too large (max: {} bytes)'.format(MAX_SIZE))
data_blocks.append(buf)
buf = f.read(BUF_SIZE)
data = ''.join(data_blocks)
Python bottle - How to upload media files without DOSing the server
关于python - 限制瓶子中上传文件的大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30754447/