Php drupal实体类中的文件属性?

Php drupal实体类中的文件属性?,php,drupal,Php,Drupal,如何在drupal实体中存储文件?我有一个与用户关联的plublic密钥,所以我创建了一个APIuser实体,但我不知道公钥属性的字段是什么类型的 function api_user_schema() { $schema['api_user'] = array( 'description' => 'The base table for api_user.', 'fields' => array( 'id' => array(

如何在drupal实体中存储文件?我有一个与用户关联的plublic密钥,所以我创建了一个APIuser实体,但我不知道公钥属性的字段是什么类型的

function api_user_schema() {
    $schema['api_user'] = array(
    'description' => 'The base table for api_user.',
    'fields' => array(
        'id' => array(
            'description' => 'The primary identifier for an artwork.',
            'type' => 'serial',
            'unsigned' => TRUE,
            'not null' => TRUE,
        ),
        'public_key' => array(
            'description' => 'The primary identifier for the public key.',
            'type' => ???,
            'unsigned' => TRUE,
            'not null' => TRUE,
        )
        'created' => array(
            'description' =>
            'The Unix timestamp when the api_user was created.',
            'type' => 'int',
            'not null' => TRUE,
            'default' => 0,
        ),
        'changed' => array(
            'description' =>
            'The Unix timestamp when the api_user was most recently saved.',
            'type' => 'int',
            'not null' => TRUE,
            'default' => 0,
        ),
    ),
    'unique keys' => array(
        'id' => array('id')
    ),
    'primary key' => array('id'),
    );

    return $schema;
}

您得到的是单个数据库表的定义;Drupal没有为文件提供最上面的层,所以如果你想存储一个文件,你必须手动操作

您可以举的最好的例子是核心用户实体。它定义了
picture
属性,它是一个ID,引用
file\u managed
表中的一个条目(顺便说一句,Drupal core默认处理所有永久文件存储的方式)

这是该db列的架构定义(从):

这与你的定义非常相似

从这里开始,查看函数(定义
图片
属性的表单元素)和函数,该函数将向您展示如何执行文件上传,将文件保存在
文件管理的
表中,并将
图片
字段的提交值更改为相关的文件ID(以便根据实体自动保存)

您将主要复制这两个函数中的代码,因此不会那么棘手

'picture' => array(
  'type' => 'int',
  'not null' => TRUE,
  'default' => 0,
  'description' => "Foreign key: {file_managed}.fid of user's picture.",
)