-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uploading done. (Python is awesome.)
- Loading branch information
Showing
9 changed files
with
37 additions
and
30 deletions.
There are no files selected for viewing
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
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
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
#!/usr/bin/python | ||
import cgi, os | ||
import cgitb; cgitb.enable() | ||
import cgi, cgitb, os, base64, re; cgitb.enable() | ||
|
||
form = cgi.FieldStorage() | ||
dataUrlPattern = re.compile('data:image/png;base64,(.*)$') | ||
|
||
# A nested FieldStorage instance holds the file | ||
if form.has_key('file'): | ||
fileitem = form['file'] | ||
# Test if the file was uploaded | ||
fname = fileitem.filename | ||
if fname: | ||
fn = os.path.basename(fname) | ||
open('content/' + fn, 'wb').write(fileitem.file.read()) | ||
message = 'The file "' + fn + '" was uploaded successfully' | ||
print 'Content-Type: text/plain\n'; | ||
|
||
if form.has_key('imagedata'): | ||
imagedata = form['imagedata'].value | ||
if form.has_key('fname'): | ||
fn = form['fname'].value | ||
fn = 'content/'+os.path.basename(fn) | ||
match = dataUrlPattern.match(imagedata) | ||
if match is not None: | ||
imgb64 = match.group(1) | ||
if imgb64 is not None and len(imgb64) > 0: | ||
img = base64.b64decode(imgb64) | ||
open(fn, 'wb').write(img) | ||
os.chmod(fn, 0o0777); | ||
print '@win\nThe file "' + fn + '" was uploaded successfully (but at what cost?)' | ||
else: | ||
print '@err\nIt didn\'t work.' | ||
else: | ||
print '@err\nNot a data:uri' | ||
else: | ||
message = 'No form["file"].filename' | ||
print '@err\nNo form["filename"]' | ||
else: | ||
message = 'No form["file"]' | ||
|
||
print """\ | ||
Content-Type: text/html\n | ||
<html><body> | ||
<p>%s</p> | ||
</body></html> | ||
""" % (message) | ||
|
||
print form | ||
print '@err\nNo form["imagedata"]' |