def save(self, record_key, record_data, overwrite=True, secret_key=''):

        ''' 
            a method to create a record in the collection folder

        :param record_key: string with name to assign to record (see NOTES below)
        :param record_data: byte data for record body
        :param overwrite: [optional] boolean to overwrite records with same name
        :param secret_key: [optional] string with key to encrypt data
        :return: string with name of record

        NOTE:   record_key may only contain alphanumeric, /, _, . or -
                characters and may not begin with the . or / character.

        NOTE:   using one or more / characters splits the key into
                separate segments. these segments will appear as a
                sub directories inside the record collection and each
                segment is used as a separate index for that record
                when using the list method
                eg. lab/unittests/1473719695.2165067.json is indexed:
                [ 'lab', 'unittests', '1473719695.2165067', '.json' ]
        '''

        title = '%s.save' % self.__class__.__name__
            
    # validate inputs
        input_fields = {
            'record_key': record_key,
            'secret_key': secret_key
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
    
    # validate byte data
        if not isinstance(record_data, bytes):
            raise ValueError('%s(record_data=b"...") must be byte data.' % title)
        
    # construct and validate file path
        file_root, file_name = os.path.split(record_key)
        self.fields.validate(file_name, '.record_key_comp')
        while file_root:
            file_root, path_node = os.path.split(file_root)
            self.fields.validate(path_node, '.record_key_comp')

    # verify permissions
        if not self.permissions_write:
            raise Exception('%s requires an access_token with write permissions.' % title)
    
    # retrieve file id
        file_id, parent_id = self._get_id(record_key)
        
    # check overwrite condition
        if file_id:
            if overwrite:
                try:
                    self.drive.delete(fileId=file_id).execute()
                except:
                    raise DriveConnectionError(title)
            else:
                raise Exception('%s(record_key="%s") already exists. To overwrite, set overwrite=True' % (title, record_key))
    
    # check size of file
        import sys
        record_optimal = self.fields.metadata['record_optimal_bytes']
        record_size = sys.getsizeof(record_data)
        error_prefix = '%s(record_key="%s", record_data=b"...")' % (title, record_key)
        if record_size > record_optimal:
            print('[WARNING] %s exceeds optimal record data size of %s bytes.' % (error_prefix, record_optimal))
            
    # encrypt data
        if secret_key:
            from labpack.encryption import cryptolab
            record_data, secret_key = cryptolab.encrypt(record_data, secret_key)

    # prepare file body
        from googleapiclient.http import MediaInMemoryUpload
        media_body = MediaInMemoryUpload(body=record_data, resumable=True)
        
    # determine path segments
        path_segments = record_key.split(os.sep)
        
    # construct upload kwargs
        create_kwargs = {
            'body': {
                'name': path_segments.pop()
            },
            'media_body': media_body,
            'fields': 'id'
        }
    
    # walk through parent directories
        parent_id = ''
        if path_segments:
        
        # construct query and creation arguments
            walk_folders = True
            folder_kwargs = {
                'body': {
                    'name': '',
                    'mimeType' : 'application/vnd.google-apps.folder'
                },
                'fields': 'id'
            }
            query_kwargs = {
                'spaces': self.drive_space,
                'fields': 'files(id, parents)'
            }
            while path_segments:
                folder_name = path_segments.pop(0)
                folder_kwargs['body']['name'] = folder_name
        
        # search for folder id in existing hierarchy
                if walk_folders:
                    walk_query = "name = '%s'" % folder_name
                    if parent_id:
                        walk_query += "and '%s' in parents" % parent_id
                    query_kwargs['q'] = walk_query
                    try:
                        response = self.drive.list(**query_kwargs).execute()
                    except:
                        raise DriveConnectionError(title)
                    file_list = response.get('files', [])
                else:
                    file_list = []
                if file_list:
                    parent_id = file_list[0].get('id')
        
        # or create folder
        # https://developers.google.com/drive/v3/web/folder
                else:
                    try:
                        if not parent_id:
                            if self.drive_space == 'appDataFolder':
                                folder_kwargs['body']['parents'] = [ self.drive_space ]
                            else:
                                del folder_kwargs['body']['parents']
                        else:
                            folder_kwargs['body']['parents'] = [parent_id]
                        response = self.drive.create(**folder_kwargs).execute()
                        parent_id = response.get('id')
                        walk_folders = False
                    except:
                        raise DriveConnectionError(title)
    
    # add parent id to file creation kwargs
        if parent_id:
            create_kwargs['body']['parents'] = [parent_id]
        elif self.drive_space == 'appDataFolder':
            create_kwargs['body']['parents'] = [self.drive_space] 
    
    # modify file time
        import re
        if re.search('\\.drep$', file_name):
            from labpack.records.time import labDT
            drep_time = labDT.fromEpoch(1).isoformat()
            create_kwargs['body']['modifiedTime'] = drep_time
            
    # send create request
        try:
            self.drive.create(**create_kwargs).execute()
        except:
            raise DriveConnectionError(title)
        
        return record_key