def handle_upload(self, stream_name): results = [] stream_query = StreamModel.query(StreamModel.name==stream_name) stream = stream_query.fetch()[0] 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): picture = fieldStorage.value #self.write_data(stream, stream_name, picture) #num = num+1 num = self.add(ndb.Key('StreamModel', stream.key.id())) user_picture = PictureModel(parent = db.Key.from_path('StreamModel', stream_name)) user_picture.id = str(num) picture = images.resize(picture, 640, 800) user_picture.picture = db.Blob(picture) stream.lastUpdated = user_picture.uploadDate user_picture.lat = random.random() user_picture.lg = random.random() user_picture.put() # key = self.write_blob( # picture, result # ) # if key is not None: results.append(result) return results
def write_data(self, stream, stream_name, picture): stream.totalPicture = stream.totalPicture + 1 user_picture = PictureModel(parent = db.Key.from_path('StreamModel', stream_name)) user_picture.id = str(stream.totalPicture) picture = images.resize(picture, 320, 400) user_picture.picture = db.Blob(picture) stream.lastUpdated = user_picture.uploadDate db.put_async(user_picture)
def post(self): picture = self.request.get('file') stream_name = self.request.params['streamname'] stream_query = StreamModel.query(StreamModel.name==stream_name) stream = stream_query.fetch()[0] stream.totalPicture = stream.totalPicture + 1 user_picture = PictureModel(parent = db.Key.from_path('StreamModel', stream_name)) user_picture.id = str(stream.totalPicture) picture = images.resize(picture, 320, 400) user_picture.picture = db.Blob(picture) stream.lastUpdated = user_picture.uploadDate stream.put() user_picture.put()
def post(self): returnURL = self.request.headers['Referer'] picture = self.request.get('file') if (len(picture)>0): stream_name = re.findall('=(.*)', returnURL)[0] stream_query = StreamModel.query(StreamModel.name==stream_name) stream = stream_query.fetch()[0] if (stream.author == users.get_current_user()): stream.totalPicture = stream.totalPicture + 1 user_picture = PictureModel(parent = db.Key.from_path('StreamModel', stream_name)) user_picture.id = str(stream.totalPicture) picture = images.resize(picture, 320, 400) user_picture.picture = db.Blob(picture) stream.lastUpdated = user_picture.uploadDate user_picture.put() stream.put() self.redirect(returnURL)