def insert(blobType, release, data, content_type, **args): try: blobId = ObjectId() dbGrid = Db().getGridFs('blobs') dbGrid.put( data, content_type=content_type, filename="%s.%s" % (blobId, release), type=blobType, blobId=str(blobId), release=release, **args ) if 'activity' in args: a = ActivityFactory.get(args['activity']) if not 'blobs' in a.__dict__[release]: a.__dict__[release]['blobs'] = {} if not blobType in a.__dict__[release]['blobs']: a.__dict__[release]['blobs'][blobType] = [] a.__dict__[release]['blobs'][blobType].append(str(blobId)) ActivityFactory.update(a) except DbError: output.error('cannot access db', 503) return blobId
def update(blobId, blobType, release, data, content_type, **args): try: dbGrid = Db().getGridFs('blobs') dbGrid.put( data, content_type=content_type, filename="%s.%s" % (blobId, release), type=blobType, blobId=str(blobId), release=release, **args ) try: oldFile = dbGrid.get_version("%s.%s" % (blobId, release), -2) dbGrid.delete(oldFile._id) except NoFile: pass except CorruptGridFile: pass except DbError: output.error('cannot access db', 503)