UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

80 lines (79 loc) 2.86 kB
/// <reference types="node" /> /** * 以流式方式上传文件到腾讯云 COS(使用 putObject 简单上传) * 支持通过文件路径或 Buffer 上传,适用于大文件或流式场景 * 注意:单次上传大小限制为 5GB,超大文件请使用 uploadCOSStreamFileV2 * @param {object} config 配置信息 * @param {object} config.file 文件信息 * @param {string} [config.file.path] 文件路径(与 buffer 二选一) * @param {number} config.file.size 文件大小(字节) * @param {Buffer} [config.file.buffer] 文件 Buffer(与 path 二选一) * @param {string} config.key COS 对象键(如 'images/test.png') * @param {string} config.secretId COS secretId * @param {string} config.secretKey COS secretKey * @param {string} config.bucket COS bucket * @param {string} config.region COS region * @returns {Promise<any>} 上传结果 * @example * ```ts * await uploadCOSStreamFile({ * file: { path: '/tmp/test.png', size: 1024 }, * key: 'images/test.png', * secretId: 'xxx', * secretKey: 'xxx', * bucket: 'my-bucket-1250000000', * region: 'ap-guangzhou', * }); * ``` */ export declare function uploadCOSStreamFile({ file, key, secretId, secretKey, bucket, region, }: { secretId: string; secretKey: string; bucket: string; region: string; file: { path?: string; size: number; buffer?: Buffer; }; key: string; }): Promise<unknown>; /** * 以高级上传方式上传文件到腾讯云 COS(使用 uploadFile,SDK 自动决定分块或简单上传) * 适用于大文件上传,支持自动分块和断点续传 * @param {object} config 配置信息 * @param {object} config.file 文件信息 * @param {string} config.file.path 文件路径(必填) * @param {number} config.file.size 文件大小(字节) * @param {string} config.key COS 对象键(如 'images/test.png') * @param {string} config.secretId COS secretId * @param {string} config.secretKey COS secretKey * @param {string} config.bucket COS bucket * @param {string} config.region COS region * @param {number} [config.sliceSize=5242880] 分块大小,默认 5MB * @returns {Promise<any>} 上传结果 * @example * ```ts * await uploadCOSStreamFileV2({ * file: { path: '/tmp/large-file.zip', size: 104857600 }, * key: 'files/large-file.zip', * secretId: 'xxx', * secretKey: 'xxx', * bucket: 'my-bucket-1250000000', * region: 'ap-guangzhou', * sliceSize: 1024 * 1024 * 10, // 10MB * }); * ``` */ export declare function uploadCOSStreamFileV2({ file, key, secretId, secretKey, bucket, region, sliceSize, }: { secretId: string; secretKey: string; bucket: string; region: string; file: { path?: string; size: number; }; key: string; sliceSize?: number; }): Promise<unknown>;