import tornado.ioloop
import tornado.web
import os
size = 128, 128
static_files_path = r'./data/web/upload/'
def endWith(s,*endstring):
array = map(s.endswith,endstring)
if True in array:
return True
else:
return False
class UploadFileHandler(tornado.web.RequestHandler):
def get(self):
taskID=self.get_argument('taskID')
taskDir = os.path.abspath(static_files_path+taskID+'/')
isExists=os.path.exists(taskDir)
imageList=[]
if isExists:
filenames=os.listdir(taskDir)
for name in filenames:
if endWith(name,'png','gif','jpeg','jpg'):
imageList.append(name)
self.render("upload-file.html",taskID=taskID, static_files_path=static_files_path,items=imageList)
def post(self):
taskID=self.get_argument('taskID')
taskDir = os.path.abspath(static_files_path+taskID+'/')
isExists=os.path.exists(taskDir)
if not isExists:
os.makedirs(taskDir)
os.makedirs(taskDir+'/s_img')
print taskDir+u' is Created'
file_dict_list = self.request.files['file']
for file_dict in file_dict_list:
filename = file_dict["filename"]
f = open(taskDir+'/'+filename, "wb")
f.write(file_dict["body"])
f.close()
if(self.get_argument('submit')=='web'):
self.redirect('./upload?taskID='+taskID)
else:
self.write('{"status":"ok"}')
settings = {
"static_path": static_files_path,
}
application = tornado.web.Application([
(r"/upload", UploadFileHandler),
], **settings)
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
import tornado.web
import os
size = 128, 128
static_files_path = r'./data/web/upload/'
def endWith(s,*endstring):
array = map(s.endswith,endstring)
if True in array:
return True
else:
return False
class UploadFileHandler(tornado.web.RequestHandler):
def get(self):
taskID=self.get_argument('taskID')
taskDir = os.path.abspath(static_files_path+taskID+'/')
isExists=os.path.exists(taskDir)
imageList=[]
if isExists:
filenames=os.listdir(taskDir)
for name in filenames:
if endWith(name,'png','gif','jpeg','jpg'):
imageList.append(name)
self.render("upload-file.html",taskID=taskID, static_files_path=static_files_path,items=imageList)
def post(self):
taskID=self.get_argument('taskID')
taskDir = os.path.abspath(static_files_path+taskID+'/')
isExists=os.path.exists(taskDir)
if not isExists:
os.makedirs(taskDir)
os.makedirs(taskDir+'/s_img')
print taskDir+u' is Created'
file_dict_list = self.request.files['file']
for file_dict in file_dict_list:
filename = file_dict["filename"]
f = open(taskDir+'/'+filename, "wb")
f.write(file_dict["body"])
f.close()
if(self.get_argument('submit')=='web'):
self.redirect('./upload?taskID='+taskID)
else:
self.write('{"status":"ok"}')
settings = {
"static_path": static_files_path,
}
application = tornado.web.Application([
(r"/upload", UploadFileHandler),
], **settings)
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()