40 lines
1.1 KiB
Plaintext
40 lines
1.1 KiB
Plaintext
|
|
syntax = "v1"
|
|||
|
|
|
|||
|
|
info (
|
|||
|
|
title: "上传"
|
|||
|
|
desc: "图片上传,用于行驶证等需 URL 的接口"
|
|||
|
|
version: "v1"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
type (
|
|||
|
|
UploadImageReq {
|
|||
|
|
ImageBase64 string `json:"image_base64" validate:"required"` // 图片 base64(不含 data URL 前缀)
|
|||
|
|
}
|
|||
|
|
UploadImageResp {
|
|||
|
|
Url string `json:"url"` // 可公网访问的图片 URL
|
|||
|
|
}
|
|||
|
|
ServeUploadedFileReq {
|
|||
|
|
FileName string `path:"fileName"` // 文件名,如 uuid.jpg
|
|||
|
|
}
|
|||
|
|
// 实际由 Handler 根据 FilePath/ContentType 写文件流,不返回 JSON
|
|||
|
|
ServeUploadedFileResp {
|
|||
|
|
FilePath string `json:"-"` // 内部:本地文件路径
|
|||
|
|
ContentType string `json:"-"` // 内部:Content-Type
|
|||
|
|
}
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
@server (
|
|||
|
|
prefix: api/v1
|
|||
|
|
group: upload
|
|||
|
|
)
|
|||
|
|
service main {
|
|||
|
|
@doc "上传图片,返回可访问 URL(如行驶证);限制 3MB"
|
|||
|
|
@handler UploadImage
|
|||
|
|
post /upload/image (UploadImageReq) returns (UploadImageResp)
|
|||
|
|
|
|||
|
|
@doc "访问已上传文件(供第三方或前端通过返回的 URL 拉取)"
|
|||
|
|
@handler ServeUploadedFile
|
|||
|
|
get /upload/file/:fileName (ServeUploadedFileReq) returns (ServeUploadedFileResp)
|
|||
|
|
}
|
|||
|
|
|