|
|
## 1.1 File API 概述
|
|
|
- File API 是所有file接口的统称,主要为各种Entity type文件字段类型提供文件功能。
|
|
|
- File API
|
|
|
- 增加单个file
|
|
|
- 新增单个file接口:[/portal/api/v2/{entity_type}/{bundle}/{file_field_name}: POST](https://note.youdao.com/)
|
|
|
## 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" }
|
|
|
]
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|