Image API - StudioAquatan/django_sample_api GitHub Wiki
method | header(Content-Type ) |
param | response |
---|---|---|---|
GET | application/json |
- | HTTP_200_OK |
POST | multipart/form-data |
file : Upload imagename : File name |
HTTP_201_CREATED see /api/v1/images/<pk:int>
|
{
"count": 2,
"next": "url to next page or null",
"previous": "url to next page or null",
"results": [
{
"pk": 2,
"name": "table",
"file": "http://example.com/media/images/fd883ff293434e7db82380bc6906a212.JPG",
"created_at": "2018-05-26T21:21:17.733848+09:00"
},
{
"pk": 1,
"name": "test",
"file": "http://example.com/media/images/1c52d898d1db4db689fb38a406bd1cd1.jpeg",
"created_at": "2018-05-26T21:11:34.686626+09:00"
}
]
}
multipart/form-data
で画像を送信する.
primary keyで指定する.
method | header(Content-Type ) |
param | response |
---|---|---|---|
GET | application/json |
- | HTTP_200_OK |
PUT | multipart/form-data |
file : Upload imagename : File name |
HTTP_200_OK |
PATCH | multipart/form-data |
specify field to update | HTTP_200_OK |
DELETE | - | - | HTTP_204_NO_CONTENT |
{
"pk": 1,
"name": "test",
"file": "http://example.com/media/images/1c52d898d1db4db689fb38a406bd1cd1.jpeg",
"created_at": "2018-05-26T21:11:34.686626+09:00"
}
Base64でエンコードして文字列化した画像を送信するAPI(こっちの方が使いやすいか?).モデル自体は /api/v1/images/
と共通なので,どちらでアップロードしたデータも見れる.
method | header(Content-Type ) |
param | response |
---|---|---|---|
GET | application/json |
- | HTTP_200_OK |
POST | application/json |
file : Base64 textname : File name |
HTTP_201_CREATED |
{
"count": 2,
"next": "url to next page or null",
"previous": "url to next page or null",
"results": [
{
"pk": 2,
"name": "table",
"file": "http://example.com/media/images/fd883ff293434e7db82380bc6906a212.JPG",
"created_at": "2018-05-26T21:21:17.733848+09:00"
},
{
"pk": 1,
"name": "test",
"file": "http://example.com/media/images/1c52d898d1db4db689fb38a406bd1cd1.jpeg",
"created_at": "2018-05-26T21:11:34.686626+09:00"
}
]
}
{
"file": "iVBORw0KGgoAAAANSUhEUgAACOYAAAVKCAYAAABHT+bMAAAgAElEQVR4nOy9T68lS3If9ovMqjrn\\nd...",
"name": "file title"
}
これをPOSTする