Skip to main content

presigned_url

Function presigned_url 

Source
pub fn presigned_url(
    secret_id: &str,
    secret_key: &str,
    bucket: &str,
    region: &str,
    object_key: &str,
    method: &str,
    duration_secs: u64,
    session_token: &str,
) -> ApiResult<String>
Expand description

生成 COS 预签名 URL(STS 临时密钥 + x-cos-security-token)

使用 HMAC-SHA1 签名算法生成 COS 预签名请求 URL, 支持 GET(下载)和 PUT(上传)两种方法。

§参数

  • secret_id: STS 临时 SecretId
  • secret_key: STS 临时 SecretKey
  • bucket: COS 存储桶名
  • region: COS 区域
  • object_key: 对象 Key
  • method: HTTP 方法("get""put"
  • duration_secs: 签名有效期(秒)
  • session_token: STS SessionToken(传入 x-cos-security-token 参数)

§返回值

返回完整的预签名 URL(含所有鉴权参数)。

§Errors

  • AppError::Oss — SecretId/SecretKey 为空
  • AppError::Internal — 系统时间异常

§签名说明

签名 host 包含在签名头中,签名路径使用原始 UTF-8 编码(不 URL 编码), 但请求 URL 中的路径经过 URL 编码以兼容特殊字符。