def post(self): self.response.headers["Access-Control-Allow-Origin"] = "*" try: pn=self.request.get('pn') data = self.request.get('imgdata') decoded = data.decode('base64') user=db.GqlQuery('SELECT * FROM User WHERE phonenum = :1', pn).get() # Create the file file_name = files.blobstore.create(mime_type='image/png') # Open the file and write to it with files.open(file_name, 'a') as f: f.write(decoded) # Finalize the file. Do this before attempting to read it. files.finalize(file_name) key = files.blobstore.get_blob_key(file_name) avatar=self.request.get('avatar') if not avatar: image = model.ImageFile(imageid=model.next_image_file_id(),user=user,circle=user.circle, blob_key = key) image.put() self.response.out.write("y") else: extrapn=self.request.get('circle') extrau=db.GqlQuery('SELECT * FROM User where phonenum = :1', extrapn).get() if not extrau or not extrau.circle: tempcircle=model.Circles(cid=model.next_circle_id(),creator=pn) tempcircle.put() user.circle=tempcircle user.put() else: user.circle=extrau.circle username=self.request.get('username') user.username=username user.put() avatar=model.Avatar(user=user,blob_key=key) avatar.put() self.response.out.write("avatar success") except Exception, e: self.response.out.write(e)