# Image（图片管理）

## **POST /api/Image/UploadImage**

* **描述**: 上传图片。
* **请求体**:
  * `application/json`: `ImageRequest` 对象
  * `text/json`: `ImageRequest` 对象
  * `application/*+json`: `ImageRequest` 对象
* **响应**: 200 OK

请求示例

```
{
  "base64": "<string>"
}
```

{% hint style="warning" %}
base64不包含 data:image/png;base64,的部分
{% endhint %}

示例代码

```javascript
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "<API Key>");

const raw = JSON.stringify({
  "base64": "<string>"
});

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: raw,
  redirect: "follow"
};

fetch("//api/Image/UploadImage", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

返回示例

```json
{
  "success": true,
  "path":"/images/2f72928777ea47df97c9341256a72252.png"
}
```

{% hint style="success" %}
在这里获取到path后将其加入创建帖子的参数里
{% endhint %}

{% hint style="warning" %}
图片大小限制为3MB，建议先进行前端压缩后上传
{% endhint %}
