t-comm
Version:
专业、稳定、纯粹的工具库
48 lines (47 loc) • 1.98 kB
TypeScript
/**
* 获取腾讯云 COS 存储桶中对象的访问 URL
*
* @param secretId - 腾讯云 API 密钥 ID
* @param secretKey - 腾讯云 API 密钥 Key
* @param bucket - COS 存储桶名称
* @param region - COS 存储桶所在区域,例如 ap-beijing
* @param key - 存储在桶里的对象键(例如 1.jpg、a/b/test.txt),支持中文
* @param sign - 是否获取带签名的对象 URL,默认 true(可选)
* @param expires - 签名 URL 的有效时长,单位秒,默认 900 秒(可选)
* @param method - 请求方法,默认 GET(可选)
* @param protocol - 请求协议,可选值:http:、https:(可选)
* @param domain - 自定义域名(可选)
* @param query - 请求中的 query 参数(可选)
* @param headers - 请求中的 header 参数(可选)
* @param forceDownload - 是否强制下载,传入下载后的文件名后将拼接 response-content-disposition 参数(可选)
* @returns Promise 对象,成功时返回对象访问 URL 字符串,失败时返回错误信息
* @throws 当参数不全时会抛出错误
* @example
* ```typescript
* getCosObjectUrl({
* secretId: 'your-secret-id',
* secretKey: 'your-secret-key',
* bucket: 'examplebucket-1250000000',
* region: 'ap-beijing',
* key: '头像.jpg',
* sign: true,
* })
* .then(url => console.log(url))
* .catch(err => console.error(err));
* ```
*/
export declare function getCosObjectUrl({ secretId, secretKey, bucket, region, key, sign, expires, method, protocol, domain, query, headers, forceDownload, }: {
secretId: string;
secretKey: string;
bucket: string;
region: string;
key: string;
sign?: boolean;
expires?: number;
method?: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS';
protocol?: string;
domain?: string;
query?: Record<string, string | number | boolean>;
headers?: Record<string, string | number | boolean>;
forceDownload?: string;
}): Promise<string>;