def post(self): user_email = self.request.get(IDENTIFIER_USER_EMAIL) stream_id = self.request.get(IDENTIFIER_STREAM_ID) description = self.request.get(IDENTIFIER_STREAM_DESC) location = self.request.get(IDENTIFIER_LOCATION) print 'UploadImageService >> get upload image request ', len(self.get_uploads()) for upload in self.get_uploads(): #get the blob store object # upload = self.get_uploads()[0] image_id = uuid.uuid4() print "UploadImageService >> Upload new image with blob_key: " + str(upload.key()) if not location: # Generate a random location - Phase II requirement location = ndb.GeoPt(random.uniform(-90, 90), random.uniform(0, 90)) else: loc_cor = location.split("_") if len(loc_cor)!=2: print "length of the location parameter is not 2. (", location, ")" location = ndb.GeoPt(long(float(loc_cor[0])), long(float(loc_cor[1]))) user_image = Image(user_email=user_email, img_id=str(image_id), content=description, blob_key=upload.key(), location=location) # stream_lst = Stream.query(Stream.user_id == user_id, Stream.stream_id == stream_id).fetch() # cur_stream = stream_lst[0] current_stream = Stream().get_stream(stream_id) if current_stream: print "UploadImageService >> stream id:", stream_id, ", added image id: ", str(image_id) current_stream.addImage(key=user_image.img_id, image=user_image) print "UploadImageService >> blob_key_lst after adding: ", current_stream.blob_key_lst else: print "UploadImageService >> Fail to add user photo ", user_image, "to stream ", stream_id