def POST(self): x = web.input() taskID = x["taskID"] photoID = x.get("photoID") sequence = x.get("sequence") isOriginal = x.get("isOriginal") #x = web.input(myfile={}) #web.debug('data:%s', web.data()[:100]); pos = web.data()[:50].find('base64,'); data = web.data()[pos+7:].decode('base64') storedDir = '/home/ec2-user/root/www/static/' if not os.path.exists(storedDir): storedDir = '%s/static/%s/' % (os.getcwd(),taskID) else: storedDir = '/home/ec2-user/root/www/static/'+taskID+'/' makeIfNone(storedDir) web.debug('final stored dir:%s' % storedDir) baseURL = 'http://%s/static/%s/' % (web.ctx.env.get('HTTP_HOST'), taskID) #filePath = x['myfile'].filename.replace('\\','/').split('/')[-1] postFix = 'jpg'#filePath.split('.')[-1] hashedName = hashlib.md5('raw' + str(datetime.now(chinaTime))).hexdigest() + '.' + postFix imageFileName = storedDir+hashedName; fout = open(imageFileName, 'w') fout.write(data) fout.close() #ImageUtil.resize(imageFileName, 60, 'tb') ImageUtil.resize(imageFileName, 60, 'tb') #storedPhoto['screenURL'] = baseURL+hashedName remoteURL = baseURL + hashedName storedPhoto = None if photoID: storedPhoto = MongoUtil.fetchByID('StoredPhoto', ObjectId(photoID)) oldRemoteURL = storedPhoto['remoteURL'] storedPhoto['remoteURL'] = remoteURL if isOriginal and int(isOriginal) == 1: storedPhoto['originalURL'] = remoteURL elif not storedPhoto.get('originalURL'): storedPhoto['originalURL'] = oldRemoteURL MongoUtil.update('StoredPhoto',storedPhoto) else: storedPhoto = {'taskID':taskID, 'sequence':int(sequence), 'remoteURL':remoteURL, 'originalURL':remoteURL} MongoUtil.save('StoredPhoto', storedPhoto) #task = MongoUtil.fetchByID('PhotoTask', ObjectId(taskID)) return simplejson.dumps(cleanStoredPhoto(storedPhoto))
def addPhoto(taskID, sequence, imageFile): #taskID = x["taskID"] isOriginal = True storedDir = '/home/ec2-user/root/www/static/' if not os.path.exists(storedDir): storedDir = '%s/static/%s/' % (os.getcwd(),taskID) else: storedDir = '/home/ec2-user/root/www/static/'+taskID+'/' makeIfNone(storedDir) web.debug('final stored dir:%s, %s' % (storedDir,isOriginal)) hostName = "www.pin3d.cn" baseURL = 'http://'+ hostName +'/static/'+taskID+'/' #filePath = x['myfile'].filename.replace('\\','/').split('/')[-1] postFix = replace.getSubfix(imageFile) hashedName = hashlib.md5(str(datetime.now(chinaTime))).hexdigest() + '.' + postFix destname = os.path.join(storedDir,hashedName) #cpCmd = "cp %s %s" % (shellquote(imageFile), shellquote(destname)) #cmdResult = util.executeCmd(cpCmd) #print "cmd:%s, result:%s" % (cpCmd, cmdResult) ImageUtil.squareCrop(imageFile, destname) ImageUtil.resize(destname, 80, 'tb') ImageUtil.resize(destname, 180, 'cv') ImageUtil.resize(destname, 640, 'nm') #storedPhoto['screenURL'] = baseURL+hashedName remoteURL = baseURL + hashedName storedPhoto = { 'taskID':taskID, 'sequence':int(sequence), 'remoteURL':remoteURL, 'originalURL':remoteURL} MongoUtil.save('StoredPhoto', storedPhoto) return remoteURL
def createAllImage(fullPath): print "generate image for path:%s" % fullPath try: ImageUtil.resize(fullPath, 80, 'tb') ImageUtil.resize(fullPath, 180, 'cv') ImageUtil.resize(fullPath, 640, 'nm') except: print 'encounter error'