# 生成预签名上传地址

> 按文件大小申请一组分片上传用的预签名地址,每个分片一个地址。

POST
  https://platform.ikho.cn/developer/api/open/partner/files/upload/generate-presigned-urls
  试一试 

  
## 鉴权

  

  
    Authorization
    string
    header
    必填
    
  

  Bearer 加上用户访问令牌。

  

  

  
    Content-Type
    string
    header
    必填
    默认 application/json
  

  请求内容类型。

  

  
## 请求体

  

  
    filesize
    integer
    
    必填
    
  

  文件总大小,单位为字节。决定返回多少个分片。

  

  

  
    filetype
    string
    
    必填
    
  

  音频文件扩展名,取值 mp3、m4a 或 wav。

  

  
## 响应

  

  
    FileId
    string
    
    
    
  

  本次上传文件的标识,合并时需回传。

  

  

  
    UploadId
    string
    
    
    
  

  本次分片上传会话的标识,合并时需回传。

  

  

  
    ChunkSize
    integer
    
    
    
  

  每个分片的大小,单位为字节。文件应按此大小切片。

  

  

  
    Parts
    array
    
    
    
  

  分片列表,每个分片一个预签名地址。

  子属性
    

  
    PartNumber
    integer
    
    
    
  

  分片序号,从 1 开始。

  

    

  
    PresignedUrl
    string
    
    
    
  

  预授权上传地址。把该分片的原始字节直接 PUT 到此地址(无需鉴权头),再读取响应头里的 ETag。

  

  

  cURLPython
  

  

  bash
    
  

  
```
curl -X POST "https://platform.ikho.cn/developer/api/open/partner/files/upload/generate-presigned-urls" \
  -H "Authorization: Bearer $USER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "filesize": 10485760,
    "filetype": "mp3"
  }'
```

  ts
    
  

  
```
import requests

resp = requests.post(
    class="tk-str">"https:class="tk-cmt">//platform.ikho.cn/developer/api/open/partner/files/upload/generate-presigned-urls",
    headers={
        class="tk-str">"Authorization": class="tk-str">"Bearer " + user_token,
        class="tk-str">"Content-Type": class="tk-str">"application/json",
    },
    json={class="tk-str">"filesize": 10485760, class="tk-str">"filetype": class="tk-str">"mp3"},
)
plan = resp.json()
print(plan[class="tk-str">"ChunkSize"], len(plan[class="tk-str">"Parts"]))
```

  

  200 响应示例
    
  

  
```
{
  "FileId": "file_9f3c1a",
  "UploadId": "upload_7b2e5d",
  "ChunkSize": 5242880,
  "Parts": [
    { "PartNumber": 1, "PresignedUrl": "https://storage.ikho.cn/upload/9f3c1a/1?..." },
    { "PartNumber": 2, "PresignedUrl": "https://storage.ikho.cn/upload/9f3c1a/2?..." }
  ]
}
```
