Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
P portal
  • Project overview
    • Project overview
    • Details
    • Activity
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Create a new issue
  • Jobs
  • Issue Boards
Collapse sidebar
  • 科探开源
  • portal
  • Wiki
    • 门户v2 api 文档
  • 09.File API v2

Last edited by asdu Dec 21, 2020
Page history

09.File API v2

1.1 File API 概述

  • File API 是所有file接口的统称,主要为各种Entity type文件字段类型提供文件功能。
  • File API
    • 增加单个file
  • 新增单个file接口:/portal/api/v2/{entity_type}/{bundle}/{file_field_name}: POST

1.2.File API 新增单个数据

POST /portal/api/v2/{{resource}}/{{news}}/{{field_image}}? HTTP/1.1
Host: etl.dd:8083
Content-Type:  application/octet-stream
Authorization: Bearer 49353835a83f30b26f81dc2351330a4b
Content-Disposition: file; filename="xxxxx.png"

"<file contents here> [… binary file data …]"

1.2.1 响应数据

{
    "jsonapi": {
        "version": "1.0",
        "meta": {
            "links": {
                "self": {
                    "href": "http://jsonapi.org/format/1.0/"
                }
            }
        }
    },
    "data": {
        "type": "file--file",
        "id": "a87f5175-a21d-4bf5-ace0-d7e14a724c0f", //{{uuid}}
        "links": {
            "self": {
                "href": "http://etl.dd:8083/en/portal/api/v2/file/file/a87f5175-a21d-4bf5-ace0-d7e14a724c0f"
            }
        },
        "attributes": {
            "drupal_internal__fid": 2,
            "langcode": "en",
            "filename": "xxxxx.png",
            "uri": {
                "value": "private://resource/image/2020-07/xxxxx.png",
                "url": "/system/files/resource/image/2020-07/xxxxx.png"
            },
            "filemime": "image/png",
            "filesize": 314502,
            "status": false,
            "created": "2020-07-24T02:50:38+00:00",
            "changed": "2020-07-24T02:50:38+00:00"
        },
        "relationships": {
            "uid": {
                "data": {
                    "type": "user--user",
                    "id": "acad55de-a9f1-49e3-b1ee-ec13ea9eaf4a"
                },
                "links": {
                    "related": {
                        "href": "http://etl.dd:8083/en/portal/api/v2/file/file/a87f5175-a21d-4bf5-ace0-d7e14a724c0f/uid"
                    },
                    "self": {
                        "href": "http://etl.dd:8083/en/portal/api/v2/file/file/a87f5175-a21d-4bf5-ace0-d7e14a724c0f/relationships/uid"
                    }
                }
            }
        }
    },
    "links": {
        "self": {
            "href": "http://etl.dd:8083/en/portal/api/v2/file/file/a87f5175-a21d-4bf5-ace0-d7e14a724c0f"
        }
    }
}

1.2.2.如何关联到自己的实体内容类型字段里

POST /portal/api/v2/resource/news? HTTP/1.1
Host: etl.dd:8083
Content-Type: application/vnd.api+json
Authorization: Bearer 49353835a83f30b26f81dc2351330a4b

{
  "data": {
    "type": "resource--news",
    "attributes": {
      "title": "明天召开教职工大会23image2ttttfile",
      "url_redirection": {"uri":"http://test.com/eww.html"},
      "published_date":"2020-10-13T04:48:02+00:00",
      "body":"<p>信息描述支持html</p>",
      "status":1
      
    },
    "relationships": {
      "field_access_roles": {
        "data": { "type": "user_role--user_role", "id": "b063ed18-e05f-4694-a2a3-0f2e1c584efd" }
      },
      "field_department": {
        "data": { "type": "taxonomy_term--department", "id": "2d062779-4d71-47e1-8519-e8350659158c" }
      },
      "field_category": {
        "data": { "type": "taxonomy_term--resource_category", "id": "56bcc47b-9e7a-42d3-9534-fd3bd2d0e384" }
      },
      "field_image": {
        "data": { "type": "file--file", "id": "a87f5175-a21d-4bf5-ace0-d7e14a724c0f" } //{{uuid}}
      },
      "field_attachment": {
        "data": [
            { "type": "file--file", "id": "9df7d33d-3047-4978-adba-b528272aaca4" },
            { "type": "file--file", "id": "9df7d33d-3047-4978-adba-b528272aaca4" }
            ]
      }
      
    }
  }
}
Clone repository
  • Home
  • 数据管理手册
    • 094.Views twig 配置
    • ETL01.数据管理使用手册 V2.0
    • ETL02.Source 数据请求 data_fetcher_plugin
    • ETL03.Source 解析 data_parser_plugin
    • ETL04.Source 认证插件 authentication
    • ETL05.Porcess plugins 明细
    • ETL06.URL endpoint 数据管理E
    • ETL07.Mysql 数据管理
    • ETL08.MSSQL 数据管理
    • ETL09.Oracle 数据管理
    • ETL10.Token 列表
  • 门户V2 API 文档
    • 01.Portal Rest API v2
    • 01.Resource API
    • 02.App API
View All Pages