def uploadNoInput(req): data.clearDatabase() lastID = data.writeDatabase("auto", "*****@*****.**", "auto", "auto") last = data.getEntryFromID(lastID) obj = "" fileitem = req.form['file'] if fileitem.filename: # strip leading path from file name to avoid directory traversal attacks # also prepend DB ID so filenames are unique fname = str(last['_id'])+"_"+os.path.basename(fileitem.filename) obj = data.updateFilenameFromID(last['_id'],fname) # build absolute path to files directory dir_path = os.path.join(os.path.dirname(req.filename), 'files') open(os.path.join(dir_path, fname), 'wb').write(fileitem.file.read()) #obj = analyze.histogram(last['_id']) obj = image.resize(last['_id']) obj = analyze.histogram(last['_id'], 4) message = "<HTML>" message += 'The file "%s" was uploaded, resized, and analyzed successfully' % fname #message += 'go <a href="#" onClick = "history.back()"> back </a> message += '\n<img src="'+cfg.imageWebPath+fname+'">' f = open("/srv/www/htdocs/lighting/app/control.html",'r') message += f.read() #message += '<br>debug of DB object: <br>' #for x in obj: # message +=(x+": "+str(obj[x])+"<br>") #message += "<p>" #message += "</HTML>" else: message = 'No file was uploaded' return message
def uploadAndInput(req, name, email, title, comment): data.clearDatabase() lastID = data.writeDatabase(name, email, title, comment) last = data.getEntryFromID(lastID) obj = "" fileitem = req.form['file'] if fileitem.filename: # strip leading path from file name to avoid directory traversal attacks # also prepend DB ID so filenames are unique fname = str(last['_id'])+"_"+os.path.basename(fileitem.filename) obj = data.updateFilenameFromID(last['_id'],fname) # build absolute path to files directory dir_path = os.path.join(os.path.dirname(req.filename), 'files') open(os.path.join(dir_path, fname), 'wb').write(fileitem.file.read()) #obj = analyze.histogram(last['_id']) obj = image.resize(last['_id']) obj = analyze.histogram(last['_id'], 4) message = "<HTML>" message += 'The file "%s" was uploaded, resized, and analyzed successfully' % fname message += '\n<img src="'+cfg.imageWebPath+fname+'">' message += '<br>debug of DB object: <br>' for x in obj: message +=(x+": "+str(obj[x])+"<br>") message += "<p>" message += "</HTML>" else: message = 'No file was uploaded' return message
def on_message(self, message): print message msg = json.loads(message) if msg['type'] == 'database': if msg['data']['cmd'] == 'clearDatabase': database.clearDatabase()