# 附件處理

跨模組通用的功能，可管理系統附件，包括：附件上傳、附件下載、附件刪除。

## 附件上傳

> 使用說明，以表單申請要加入附件舉例：\
> \- step1. 打這個 API 取得回傳物件\
> \- step2. 把回傳物件 push 進表單申請的 attachments 陣列\
> 回傳格式：\
> \`\`\`\
> {\
> &#x20; "fileUUID": "30381c3458faf2d31c38aed42e7c6e17",\
> &#x20; "fileName": "1.png",\
> &#x20; "fileSize": 74506,\
> &#x20; "fileMime": "image/png",\
> &#x20; "isTmp": 1\
> }\
> \`\`\`<br>

````json
{"openapi":"3.0.0","tags":[{"name":"附件處理","description":"跨模組通用的功能，可管理系統附件，包括：附件上傳、附件下載、附件刪除。"}],"servers":[{"url":"https://104demotest-api-server.hrmax.104.com.tw"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"responses":{"401":{"description":"認證失敗 (請更新 accessToken 再試一次)"},"403":{"description":"權限不足"},"440":{"description":"參數錯誤 (請檢查 parameters 或 request body 的欄位、格式是否完整及正確)"},"500":{"description":"系統異常 `{ code: 500, msg: string }`"}}},"paths":{"/api/file/attach":{"post":{"tags":["附件處理"],"summary":"附件上傳","description":"使用說明，以表單申請要加入附件舉例：\n- step1. 打這個 API 取得回傳物件\n- step2. 把回傳物件 push 進表單申請的 attachments 陣列\n回傳格式：\n```\n{\n  \"fileUUID\": \"30381c3458faf2d31c38aed42e7c6e17\",\n  \"fileName\": \"1.png\",\n  \"fileSize\": 74506,\n  \"fileMime\": \"image/png\",\n  \"isTmp\": 1\n}\n```\n","requestBody":{"require":true,"content":{"multipart/form-data":{"schema":{"type":"object","required":["funCode","attachment"],"properties":{"funCode":{"type":"string","description":"約定的功能代碼，例如：請假單=\"wf010\""},"attachment":{"type":"string","format":"binary","description":"multipart request 的 field name 必須是 'attachment'"}}}}}},"responses":{"200":{"description":"成功"},"401":{"$ref":"#/components/responses/401"},"403":{"$ref":"#/components/responses/403"},"440":{"$ref":"#/components/responses/440"},"450":{"description":"MulterError `{ code: 450, msg?: string }`"},"500":{"$ref":"#/components/responses/500"}}}}}}
````

## POST /api/file/detach

> 刪除已上傳的附件

```json
{"openapi":"3.0.0","tags":[{"name":"附件處理","description":"跨模組通用的功能，可管理系統附件，包括：附件上傳、附件下載、附件刪除。"}],"servers":[{"url":"https://104demotest-api-server.hrmax.104.com.tw"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"responses":{"401":{"description":"認證失敗 (請更新 accessToken 再試一次)"},"403":{"description":"權限不足"},"440":{"description":"參數錯誤 (請檢查 parameters 或 request body 的欄位、格式是否完整及正確)"},"500":{"description":"系統異常 `{ code: 500, msg: string }`"}}},"paths":{"/api/file/detach":{"post":{"tags":["附件處理"],"summary":"刪除已上傳的附件","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["uuid"],"properties":{"uuid":{"type":"string","description":"FILE UUID"}}}}}},"responses":{"200":{"description":"成功"},"401":{"$ref":"#/components/responses/401"},"403":{"$ref":"#/components/responses/403"},"440":{"$ref":"#/components/responses/440"},"500":{"$ref":"#/components/responses/500"}}}}}}
```

## POST /api/file/download

> 下載附件

```json
{"openapi":"3.0.0","tags":[{"name":"附件處理","description":"跨模組通用的功能，可管理系統附件，包括：附件上傳、附件下載、附件刪除。"}],"servers":[{"url":"https://104demotest-api-server.hrmax.104.com.tw"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"responses":{"401":{"description":"認證失敗 (請更新 accessToken 再試一次)"},"403":{"description":"權限不足"},"440":{"description":"參數錯誤 (請檢查 parameters 或 request body 的欄位、格式是否完整及正確)"},"500":{"description":"系統異常 `{ code: 500, msg: string }`"}}},"paths":{"/api/file/download":{"post":{"tags":["附件處理"],"summary":"下載附件","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["uuid"],"properties":{"uuid":{"type":"string","description":"FILE UUID"}}}}}},"responses":{"200":{"description":"成功"},"401":{"$ref":"#/components/responses/401"},"403":{"$ref":"#/components/responses/403"},"440":{"$ref":"#/components/responses/440"},"500":{"$ref":"#/components/responses/500"}}}}}}
```
