Created
December 16, 2012 23:28
-
-
Save tmeissner/4314180 to your computer and use it in GitHub Desktop.
Python file upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import yate | |
import cgi | |
import os | |
form = cgi.FieldStorage() | |
item = form["filename"] | |
message = 'File uploaded' | |
if item.file: | |
fout = file(str(os.getcwd()) + '/../data/drewag.pdf', 'wb') | |
filesize = 0 | |
while 1: | |
if (filesize > (1024*1024)): | |
message = "File too big, upload aborted" | |
break | |
chunk = item.file.read(1024) | |
filesize = filesize + 1024 | |
if not chunk: | |
break | |
fout.write(chunk) | |
print(yate.start_response()) | |
print("<!DOCTYPE html>\n<html>") | |
print(yate.html_header()) | |
print("<body>") | |
print(yate.para(message)) | |
print(yate.include_footer({"Home": "/projects/drewag/drewag_upload.html"})) | |
print("</body>\n</html>") | |
fout.close() | |
if message != 'File uploaded': | |
os.remove(str(os.getcwd()) + '/../data/drewag.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment