Here is my code to accept files uploaded by users:
def post(self):
logging.info('(POST) Uploading new file')
# saving file in the database
file = Files()
file.file = db.Blob(self.request.body)
file.put()
How can I avoid upload of files larger than 100Kb and which file type is not .torrent? (I believe I should verify the file’s mime type?)
You can’t prevent the file from being uploaded – by the time your request handler is executed, the file has already been uploaded. All you can do is discard the file and return an error message.
Since it appears the file is being uploaded as the body of the request, rather than from an HTML form, you can determine the content type by getting
self.request.headers["Content-Type"], and the size withlen(self.request.body).