跳转至

HTML 编辑器文件上传(HtmlEditUploadController)

UEditor 富文本编辑器对接接口:根据 action 处理图片 / 文件 / 视频上传,或回显 UEditor 配置(UeditorActionEnter)。基址为 /api(路径位于 /api/runtime/** 下)。

  • 接口类型:REST 资源(@Controller + 方法级 @ResponseBody,方法返回 void,由控制器直接写回 HttpServletResponse 输出流;正文为 JSON 字符串,Content-Type: text/json
  • 基址${myapps.context-path.runtime:}/api
  • Tag:html文件上传文件执行模块

公共说明

  • 鉴权(据源码 RuntimeMvcConfig + RestSecurityHandlerInterceptor:方法级路径 /runtime/html/edit/upload 拼接类级 /api 后位于 /api/runtime/** 下,在 RestSecurityHandlerInterceptor 覆盖范围内,且不在豁免名单(豁免名单见 login.md「公共说明 · 鉴权」)。需 accessToken(或 debugToken),可通过 Cookie / 请求头 / query 参数任一方式传递。
  • 响应结构非统一 Resource。控制器直接将 JSONObject 字符串通过 PrintWriter 写回 HttpServletResponse
  • 上传成功(action=uploadimage|uploadfile|uploadvideo):写回 { state, original, size, title, type, url }(state 为 "SUCCESS");
  • 其他 action(含配置请求):调用 UeditorActionEnter(request, rootPath).exec(),写回 UEditor 标准响应 JSON,并将 url 字段前缀拼接 contextPath
  • HTTP 状态码:类级标注 @ResponseStatus(HttpStatus.OK),成功统一返回 200。

1. HTML 编辑器文件上传

action 区分上传类型(uploadimage / uploadfile / uploadvideo),将文件保存到 <storageRoot>/uploads/htmlfield/{image|file|video}/<yyyyMMdd>/<uuid><ext>,返回 UEditor 标准响应 JSON;非上传 action 时执行 UEditor 配置入口返回。

  • 接口类型:REST 资源(multipart/form-data 文件上传,JSON 文本响应)
  • 请求方式@RequestMapping(未限定 method,支持 GET / POST 等所有方法
  • 请求路径/runtime/html/edit/upload(完整:{runtime-context}/api/runtime/html/edit/upload
  • 鉴权:是(需 accessToken,据源码)
  • Tag:html文件上传文件执行模块

请求参数

参数名 位置 类型 必填 说明
action query string UEditor action 标识:uploadimage / uploadfile / uploadvideo 触发上传;其他值走 UeditorActionEnter 配置入口
upfile body (form-data) MultipartFile 上传文件(仅 uploadimage / uploadfile / uploadvideo 时需要)

请求示例

POST /api/runtime/html/edit/upload?action=uploadimage HTTP/1.1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary
Cookie: accessToken=eyJhbGciOiJIUzI1NiJ9...

------WebKitFormBoundary
Content-Disposition: form-data; name="upfile"; filename="cover.png"
Content-Type: image/png

<二进制内容>
------WebKitFormBoundary--

响应

结构:JSON 字符串,Content-Type: text/json非统一 Resource

上传成功示例

{
  "state": "SUCCESS",
  "original": "cover.png",
  "size": "102400",
  "title": "550e8400-e29b-41d4-a716-446655440000.png",
  "type": ".png",
  "url": "/uploads/htmlfield/image/20260805/550e8400-e29b-41d4-a716-446655440000.png?from=htmlField"
}

UEditor 配置入口响应示例url 字段已前缀拼接 contextPath):

{
  "state": "SUCCESS",
  "url": "/obpm/uploads/htmlfield/image/xxx.png",
  "title": "xxx.png"
}