Skip to content

接口示例

本文档仅说明 server 提供的接口使用方式。

1. 健康检查

基础信息

名称默认值
请求方式GET
请求地址/api/healthy

响应结果

text
healthy

2. 获取文件元信息

基础信息

名称默认值说明
请求方式GET
请求地址/api/file/getFileMeta/:filename使用 params 方式传参

路径参数

字段类型是否必填说明
filenamestring必填文件名称

响应结果

字段类型说明
sizenumber文件大小
eTagstring文件唯一标识(类似 hash)
lastModifiedstring最后修改时间
namestring文件名称
json
{
  "size": 1847928,
  "eTag": "afe35b83ccd35635b9ea7dc49ba5808c282533499275c8c811da2138c90b5b38",
  "lastModified": "2025-05-06T03:10:20.391Z",
  "name": "711.jpg"
}

Curl 示例

bash
curl "http://localhost:3100/api/file/getFileMeta/711.jpg"

3. 下载文件

基础信息

名称默认值
请求方式POST
请求地址/api/file/download

Request Headers

标头是否必填说明示例
Range按字节范围下载文件分片;不传时返回整文件,参考 Rangebytes=0-1024

Body 参数

字段类型是否必填说明
urlstring必填文件名称

请求示例:

json
{
  "url": "711.jpg"
}

Query 参数

字段类型是否必填说明
errorstring1 时返回模拟错误结果

响应说明

不传 Range

返回整文件流。

Range

返回分片文件流,状态码为 206 Partial Content

响应头:

标头示例说明
Content-Rangebytes 0-1024/1847928当前返回的字节范围,参考 Content-Range
Content-Length1025当前响应体长度,参考 Content-Length
ETagafe35b83ccd3b9....c8c811da2138c90b5b38文件唯一标识,参考 ETag
Content-Dispositionattachment; filename*=UTF-8''711.jpg文件名信息,参考 Content-Disposition

完整响应头示例:

text
access-control-allow-credentials: true
access-control-allow-origin: http://localhost:3100
access-control-expose-headers: Content-Range,Content-Disposition,Etag,Content-Type
connection: keep-alive
content-disposition: attachment; filename*=UTF-8''711.jpg
content-length: 1025
content-range: bytes 0-1024/1847928
content-type: application/octet-stream
date: Wed, 07 May 2025 07:55:08 GMT
etag: afe35b83ccd35635b9ea7dc49ba5808c282533499275c8c811da2138c90b5b38
keep-alive: timeout=5
vary: Origin
x-powered-by: Express

模拟失败时

?error=1 时返回错误结果,状态码为 200

json
{
  "code": "00003",
  "message": "模拟下载失败"
}

Curl 示例

整文件下载

bash
curl -X POST "http://localhost:3100/api/file/download" \
  -H "Content-Type: application/json" \
  -d '{"url":"711.jpg"}' \
  -o 711.jpg

分片下载

bash
curl -X POST "http://localhost:3100/api/file/download" \
  -H "Content-Type: application/json" \
  -H "Range: bytes=0-1024" \
  -d '{"url":"711.jpg"}' \
  -i

模拟失败

bash
curl -X POST "http://localhost:3100/api/file/download?error=1" \
  -H "Content-Type: application/json" \
  -d '{"url":"711.jpg"}'

4. Mock 接口(Vercel)

Swagger 文档

https://sharding-download-server.vercel.app/api/

Base URL

https://sharding-download-server.vercel.app

可用接口

  • GET /api/healthy
  • GET /api/file/getFileMeta/:filename
  • POST /api/file/download

NOTE

参数和响应格式参考上面的接口说明。

Last updated: