Validate template size during download

The API downloads the entire template before validating it. For a 100 MB
file, this causes the API process to use several hundred megabytes of
memory. If several requests like this come in simultaneously, the API
server will run out of memory.

Closes-Bug: #1233366

Change-Id: I453274d62e71b3f860322dfcd98c2830ef039e9b