Skip to content

接口示例

1. 获取文件元信息

基础信息

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

响应结果

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

2. 获取文件流

基础信息

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

Request Headers

标头示例
RangeRange"Range: bytes=0-1023"

post请求参数

字段类型是否必填说明
urlstring | number必填文件obs地址,或者业务中对应的文件id等等

query请求参数(mock失败请求)

字段类型是否必填说明
errorstring非必填值传"1"时返回错误结果,否则返回正常文件流

Response Headers

标头示例说明
Content-rangebytes 1-1000/288888Content-Range
Content-Length288888Content-Length
ETagafe35b83xxx...xxxxxxETag
Content-Dispositionattachment; filename*=UTF-8''711.jpgContent-Disposition

响应结果

成功时返回文件流 status206

失败时返回结果status200

json
{
  "code": "00003",
  "message": "模拟文件下载错误"
}

完整Curl示例

bash
curl -X 'POST' \
  'http://localhost:3100/api/file/download?error=2' \
  -H 'accept: application/json' \
  -H 'Range: bytes=0-1024' \
  -H 'Content-Type: application/json' \
  -d '{
  "url": "711.jpg"
}'
bash
## Response status: 206,  Body: blob
## Response headers 

accept-ranges: bytes 
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

3. Mock接口(vercel)

swagger接口文档

baseUrl

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

meta接口

GET: /api/file/getFileMeta/:filename

download接口

POST: /api/file/download

参考

请求方式、参数、响应结果参考接口1,接口2

Last updated: