tencent cloud

对象存储

动态与公告
产品动态
产品公告
产品简介
产品概述
功能概览
应用场景
产品优势
基本概念
地域和访问域名
规格与限制
产品计费
计费概述
计费方式
计费项
免费额度
计费示例
查看和下载账单
欠费说明
常见问题
快速入门
控制台快速入门
COSBrowser 快速入门
用户指南
创建请求
存储桶
对象
数据管理
批量处理
全球加速
监控与告警
运维中心
数据处理
内容审核
智能工具箱
数据工作流
应用集成
工具指南
工具概览
环境安装与配置
COSBrowser 工具
COSCLI 工具
COSCMD 工具
COS Migration 工具
FTP Server 工具
Hadoop 工具
COSDistCp 工具
HDFS TO COS 工具
GooseFS-Lite 工具
在线辅助工具
自助诊断工具
实践教程
概览
访问控制与权限管理
性能优化
使用 AWS S3 SDK 访问 COS
数据容灾备份
域名管理实践
图片处理实践
COS 音视频播放器实践
工作流实践
数据直传
内容审核实践
数据安全
数据校验
大数据实践
COS 成本优化解决方案
在第三方应用中使用 COS
迁移指南
本地数据迁移至 COS
第三方云存储数据迁移至 COS
以 URL 作为源地址的数据迁移至 COS
COS 之间数据迁移
Hadoop 文件系统与 COS 之间的数据迁移
数据湖存储
云原生数据湖
元数据加速
数据加速器 GooseFS
数据处理
数据处理概述
图片处理
媒体处理
内容审核
文件处理
文档处理
故障处理
获取 RequestId 操作指引
通过外网上传文件至 COS 缓慢
访问 COS 时返回403错误码
资源访问异常
POST Object 常见异常
API 文档
简介
公共请求头部
公共响应头部
错误码
请求签名
操作列表
Service 接口
Bucket 接口
Object 接口
批量处理接口
数据处理接口
任务与工作流
内容审核接口
云查毒接口
SDK 文档
SDK 概览
准备工作
Android SDK
C SDK
C++ SDK
.NET(C#) SDK
Flutter SDK
Go SDK
iOS SDK
Java SDK
JavaScript SDK
Node.js SDK
PHP SDK
Python SDK
React Native SDK
小程序 SDK
错误码
鸿蒙(Harmony) SDK
终端 SDK 质量优化
安全与合规
数据容灾
数据安全
访问管理
常见问题
热门问题
一般性问题
计费计量问题
域名合规问题
存储桶配置问题
域名和 CDN 问题
文件操作问题
日志监控问题
权限管理问题
数据处理问题
数据安全问题
预签名 URL 问题
SDK 类问题
工具类问题
API 类问题
服务协议
Service Level Agreement
隐私政策
数据处理和安全协议
联系我们
词汇表

Using Smart Compression through API

PDF
Modo Foco
Tamanho da Fonte
Última atualização: 2026-01-19 11:35:26

Feature Description

Smart Image Compression intelligently determines the subjective quality of images and performs automatic adjustment. Without changing the original format of the image, it significantly reduces the file size compared to the original while maintaining the visual quality as close to the original as possible. This helps you reduce image access traffic and improve image loading speed. The feature supports the following processing methods:
Processing during download
Processing during upload
Processing in the cloud

Authorization Description

When used with a sub-account, the ci:SetImageSlim permission is required. For details, see Cloud Infinite action.
Process during download: Set action to cos:GetObject in the authorization policy.
Process upon upload: Set action to cos:PutObject in the authorization policy.
Process data in the cloud: Set action to cos:PutObject in the authorization policy.
Note:
The resource for GetObject corresponds to the source file, and the resource for PutObject corresponds to the transferred file.

Service Activation

Using this feature requires enabling Cloud Infinite in advance and binding a bucket. For details, see Binding a Bucket.
Use this feature requires enabling the Smart Compression API functionality in advance via the console or API. For details, see Smart Image Compression.

Use Limits

When using this API, please confirm the relevant restrictions first. For details, see Specifications and Limits.
Does not support processing images in COS Archive Storage or Deep Archive Storage. If you need to process such files, please restore archived files.

Fee Description

Smart Image Compression is a paid service. The incurred fees will be collected by Cloud Infinite. For detailed billing information, see Image Processing Fees.
If "process during download" is adopted and the download is performed via the public network, the call will incur traffic charges.
If the image is stored in the COS Infrequent Access storage, the API call will generate COS data retrieval fees.

Interface Format

Processing during download

GET /<ObjectKey>?imageSlim HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: <GMT Date>
Authorization: <Auth String>

Processing during upload

PUT /<ObjectKey> HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: GMT Date
Authorization: Auth String
Pic-Operations:
{
"is_pic_info": 1,
"rules": [{
"fileid": "exampleobject.jpg",
"rule": "imageSlim"
}]
}

Processing in the cloud

POST /<ObjectKey>?image_process HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: GMT Date
Content-length: Size
Authorization: Auth String
Pic-Operations:
{
"is_pic_info": 1,
"rules": [{
"fileid": "exampleobject.jpg",
"rule": "imageSlim"
}]
}
Note:
Authorization: Carries authentication information for verifying the legitimacy of requests. The Pic-Operations header must include the signature information. For details, see the Request Signature document.
Pic-Operations is a JSON format string. Specific parameter information can be found in Image Processing Mechanism Introduction.
When fileid is the same as ObjectKey, the processed image will overwrite the original stored image; when they are different, the original image and the processed image will be stored separately.
The value of fileid needs to be URL-encoded.

Processing Parameter Description

Parameter
Definition
Required
ObjectKey
Object file name, for example: folder/sample.jpg.
Yes
imageSlim
Fixed parameters, means smart compression.
Yes
Note:
When using processing during download, you can determine whether the image has been compressed by checking the X-Slimflag response header. This response header contains the following three values:
0: Indicates compression failed;
1: Indicates compression succeeded;
2: Indicates no compression was performed, and the original image was returned.

Real Case

Note:
The actual cases in this document contain only processing during download. This type of processing will not save the processed images to the bucket. If you need saving, you can refer to the Image Processing Mechanism Introduction document and configure processing during upload or processing in the cloud.
Assume the original image format is png, the image size is 1335.2 KB, as shown below:

img


Perform Smart Image Compression on the image, the request URL is as follows:
http://example-1258125638.cos.ap-shanghai.myqcloud.com/sample.png?imageSlim
Output:

img


Compression Rate Comparison
Format
Image Size
png (original image)
1335.2KB
png (Smart Compressed image)
549KB (compression rate 58.88%)

Ajuda e Suporte

Esta página foi útil?

comentários