from bottle_ import * import cgi cgi.PATCH = False TARGET = r'C:\Users\admin\Documents\Python\target' @route("/url-get") def proc_get(): return """ Get one file

Scenario: one file

Select a file:

""" @route("/url-post", method='POST') def proc_post(): fs = request.files.data # type cgi.FieldStorage fs_file_saveto(fs, TARGET) file_saveas(fs.file, os.path.join(TARGET, 'upload')) return """ File posted

Upload succeeded!

You uploaded %s (%d %d bytes).

""" % (fs.filename, file_size(fs.file), file_size(fs)) run(host='localhost', port=10080, debug=True) # result of uploading test2.txt ## Upload succeeded! ## ## You uploaded test2.txt (61 61 bytes). # result of uploading same file, renamed to test2.mht ## Error 500: Internal Server Error ## ## Sorry, the requested URL 'http://localhost:10080/url-post' caused an error: ## ## Internal Server Error ## Exception: ## ## ValueError("Invalid boundary in multipart form: b''",) ## Traceback: ## ## Traceback (most recent call last): ## File "c:\python32\lib\site-packages\bottle.py", line 787, in _handle ## return route.call(**args) ## File "c:\python32\lib\site-packages\bottle.py", line 1577, in wrapper ## rv = callback(*a, **ka) ## File "cgibug.py", line 28, in proc_post ## fs = request.files.data # type cgi.FieldStorage ## File "c:\python32\lib\site-packages\bottle.py", line 162, in __get__ ## if key not in storage: storage[key] = self.getter(obj) ## File "c:\python32\lib\site-packages\bottle.py", line 1032, in files ## for name, item in self.POST.allitems(): ## File "c:\python32\lib\site-packages\bottle.py", line 162, in __get__ ## if key not in storage: storage[key] = self.getter(obj) ## File "c:\python32\lib\site-packages\bottle.py", line 1102, in POST ## data = FieldStorage(**args) ## File "c:\python32\lib\cgi.py", line 544, in __init__ ## self.read_multi(environ, keep_blank_values, strict_parsing) ## File "c:\python32\lib\cgi.py", line 692, in read_multi ## self.encoding, self.errors) ## File "c:\python32\lib\cgi.py", line 544, in __init__ ## self.read_multi(environ, keep_blank_values, strict_parsing) ## File "c:\python32\lib\cgi.py", line 658, in read_multi ## raise ValueError('Invalid boundary in multipart form: %r' % (ib,)) ## ValueError: Invalid boundary in multipart form: b''