def handle_upload(self): results = [] blob_keys = [] for name, fieldStorage in self.request.POST.items(): if type(fieldStorage) is unicode: continue result = {} result['name'] = re.sub( r'^.*\\', '', fieldStorage.filename ) result['type'] = fieldStorage.type result['size'] = self.get_file_size(fieldStorage.file) if self.validate(result): blob_key = str( self.write_blob(fieldStorage.value, result) ) blob_keys.append(blob_key) #use the images API to get a permanent serving URL if the file is an image results.append(result) streamId = self.request.get('streamId') loc = (self.request.get('lat'), self.request.get('lon')) stream = cStream.query(cStream.streamId == int(streamId)).get() if stream: for key in blob_keys: blobKey = blobstore.BlobKey(str(key)) imageId = stream.getNextImageId() cImage.addImage(stream.streamId, imageId, blobKey, loc) stream.images.insert(0,imageId) stream.put() return results
def post(self): result = [] for image in cImage.query(): stream = cStream.query(cStream.streamId == image.streamId).get() if (stream): url = images.get_serving_url(image.blobKey) result.append({'streamId': image.streamId, 'streamname': stream.streamName, 'url': url, 'lat': image.lat, 'lon': image.lon}) self.response.write(json.dumps(result))
def get(self): logging.info("MapDate") result = [] for image in cImage.query(): lon_offset = random.uniform(0, 0.000378075) lat_offset = random.uniform(0, 0.00077784061) result.append({'img': images.get_serving_url(image.blobKey), 'lat': image.lat + lat_offset, 'lon': image.lon + lon_offset, 'timestamp': ",".join((str(image.creationDate.month), str(image.creationDate.day), str(image.creationDate.year)))}) logging.info({'imageList': result}) self.response.write(self.request.get("callback") + "(" + json.dumps({'imageList': result}) + ")")
def post(self): #which takes a stream id and a page range and returns a #list of URLs to images, and a page range streamId = self.request.get('streamId') startPage = int(self.request.get('start_page')) endPage = int(self.request.get('end_page')) BlobKeyList = [] result = cStream.query(cStream.streamId == int(streamId)) stream = result.get() logging.info("in viewstream") imageURLs = [] if stream: i = 0 cStream.addViewToStream(int(streamId)) for x in range(0,len(stream.images)): if i >= startPage and i < endPage: image = cImage.query(cImage.imageId == stream.images[x]).get() imageURLs.append(images.get_serving_url(image.blobKey)) logging.info(images.get_serving_url(image.blobKey)) i = i + 1 self.response.write(json.dumps({'blob_key_list': imageURLs, 'start_page': startPage, 'end_page': endPage, 'stream_size': len(stream.images)}))