This is called "file slurping":
raw = data.file.read()
and you don't want to do it (at least in this case).
Here's a better way to read a binary file of unknown (possibly large) size:
data_blocks = []
buf = data.file.read(8192)
while buf:
data_blocks.append(buf)
buf = data.file.read(8192)
data = ''.join(data_blocks)
You may also want to stop iterating if the accumulated size exceeds some threshold.
Hope that helps!
PART 2
You asked about limiting the file size, so here's an amended version that does that:
MAX_SIZE = 10 * 1024 * 1024 # 10MB
BUF_SIZE = 8192
# code assumes that MAX_SIZE >= BUF_SIZE
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)
It's not perfect, but it's simple and IMO good enough.