OSS图片处理,是OSS对外提供的海量、安全、低成本、高可靠的图片处理服务。用户将原始图片上传保存到OSS,通过简单的 RESTful 接口,在任何时间、任何地点、任何互联网设备上对图片进行处理。图片处理提供图片处理接口,图片上传请使用上传接口。基于OSS图片处理,用户可以搭建自己的图片处理服务。
图片处理基础功能
OSS图片处理提供以下功能:
Bucket权限 | Object权限 |
公共读私有写(public-read)或 公共读写(public-read-write) | 默认(default) |
任意权限 | 公共读私有写(public-read)或 公共读写(public-read-write) |
http://bucket.<endpoint>/object?x-oss-process=image/action,parame_value
http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,w_100
http://bucket.<endpoint>/object?x-oss-process=x-oss-process=style/name
http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=style/oss-pic-style-w-100
http://bucket.<endpoint>/object?x-oss-process=image/action,parame_value/action,parame_value/...
http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,w_100/rotate,90
https://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,w_100
Bucket权限 | Object权限 |
私有读写(private) | 默认权限(default) |
任意权限 | 私有读写(private) |
aos_pool_t *p;
oss_request_options_t *options;
aos_http_request_t *req;
char *url_str;
aos_table_t *params = NULL;
aos_string_t bucket;
aos_string_t object;
apr_time_t now;
int64_t expire_time;
aos_pool_create(&p, NULL);
/* 创建并初始化options */
options = oss_request_options_create(p);
init_sample_request_options(options, AOS_FALSE);
/* 初始化参数 */
aos_str_set(&bucket, "<您的bucket名字>");
aos_str_set(&object, "<您的object名字>");
/* 图片处理 */
params = aos_table_make(p, 1);
apr_table_set(params, OSS_PROCESS, "image/resize,m_fixed,w_100,h_100");
req = aos_http_request_create(p);
req->method = HTTP_GET;
req->query_params = params;
/* 过期时间,单位秒 */
now = apr_time_now();
expire_time = now / 1000000 + 10 * 60;
/* 生成签名url */
url_str = oss_gen_signed_url(options, &bucket, &object, expire_time, req);
printf("url:%s\n", url_str);
aos_pool_destroy(p);
提示:
- 授权访问支持 自定义样式、 HTTPS、 级联处理
- oss_gen_signed_url 过期时间单位是[backcolor=transparent]秒
提示:
- 图片处理的完整代码请参考:GitHub
- SDK处理图片文件支持 自定义样式、 HTTPS、 级联处理
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t object;
oss_request_options_t *options = NULL;
aos_table_t *headers = NULL;
aos_table_t *params = NULL;
aos_table_t *resp_headers = NULL;
aos_status_t *s = NULL;
aos_string_t filename;
char *style = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, AOS_FALSE);
aos_str_set(&bucket, "<您的bucket名字>");
aos_str_set(&object, "<您的object名字>");
aos_str_set(&filename, "<处理后图片保存路径>");
params = aos_table_make(p, 1);
style = "image/resize,m_fixed,w_100,h_100";
apr_table_set(params, OSS_PROCESS, "image/resize,m_fixed,w_100,h_100");
/* 下载处理后的图片到本地文件 */
s = oss_get_object_to_file(options, &bucket, &object, headers,
params, &filename, &resp_headers);
if (aos_status_is_ok(s)) {
printf("get object to file succeeded\n");
} else {
printf("get object to file failed\n");
}
aos_pool_destroy(p);
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t object;
oss_request_options_t *options = NULL;
aos_table_t *headers = NULL;
aos_table_t *params = NULL;
aos_table_t *resp_headers = NULL;
aos_status_t *s = NULL;
aos_string_t filename;
char *style = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, AOS_FALSE);
aos_str_set(&bucket, "<您的bucket名字>");
aos_str_set(&object, "<您的object名字>");
aos_str_set(&filename, "<处理后图片保存路径>");
/* 自定义样式 */
style = "style/oss-pic-style-w-100";
params = aos_table_make(p, 1);
apr_table_set(params, OSS_PROCESS, "image/resize,m_fixed,w_100,h_100");
/* 下载处理后的图片到本地文件 */
s = oss_get_object_to_file(options, &bucket, &object, headers,
params, &filename, &resp_headers);
if (aos_status_is_ok(s)) {
printf("get object to file succeeded\n");
} else {
printf("get object to file failed\n");
}
aos_pool_destroy(p);
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t object;
oss_request_options_t *options = NULL;
aos_table_t *headers = NULL;
aos_table_t *params = NULL;
aos_table_t *resp_headers = NULL;
aos_status_t *s = NULL;
aos_string_t filename;
char *style = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, AOS_FALSE);
aos_str_set(&bucket, "<您的bucket名字>");
aos_str_set(&object, "<您的object名字>");
aos_str_set(&filename, "<处理后图片保存路径>");
/* 级联处理 */
style = "image/resize,m_fixed,w_100,h_100/rotate,90";
params = aos_table_make(p, 1);
apr_table_set(params, OSS_PROCESS, "image/resize,m_fixed,w_100,h_100");
/* 下载处理后的图片到本地文件 */
s = oss_get_object_to_file(options, &bucket, &object, headers,
params, &filename, &resp_headers);
if (aos_status_is_ok(s)) {
printf("get object to file succeeded\n");
} else {
printf("get object to file failed\n");
}
aos_pool_destroy(p);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。