OSS图片 数据处理持久化 JAVA实现

七牛及阿里云OSS图片旋转问题

上一篇文章我用了URL方式的图片旋转功能。但我需要的是一个持久化的结果。把旋转后的图片保存到OSS上,所以需要 数据持久化的操作。

数据处理持久化

ProcessObjectRequest 

https://help.aliyun.com/document_detail/55811.html

 1         key=StringUtils.substringBefore(key, "?");
 2         key=StringUtils.remove(key, BizConstants.ALIYUN_IMAGE_SITE_URL);
 3         String rotate=number+"";
 4         String o=EncodeUtil.encodeString(key);
 5         String b=EncodeUtil.encodeString(BizConstants.IMAGE_OSS_BUCKET_NAME);
 6         String style = "image/rotate,%s|sys/saveas,o_%s,b_%s";
 7         style=String.format(style, rotate,o,b);
 8         logger.debug("style========>{}",style);
 9         ProcessObjectRequest request = new ProcessObjectRequest(BizConstants.IMAGE_OSS_BUCKET_NAME, key,style);
10         try {
11             ossClient.processObject(request);
12             return Boolean.TRUE;
13         } catch (Exception e) {
14             e.printStackTrace();
15             return Boolean.FALSE;
16         }
17     

 x-oss-process=image/rotate

红色部分不需要写 style 中

com.aliyun.oss.OSSException: operation not support post: x-oss-process=image/rotate
[ErrorCode]: InvalidArgument
[RequestId]: 5BA230AC8236378C162A25E5
[HostId]: imgadrms.oss-cn-shanghai.aliyuncs.com
[ResponseError]:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>InvalidArgument</Code>
<Message>operation not support post: x-oss-process=image/rotate</Message>
<RequestId>5BA230AC8236378C162A25E5</RequestId>
<HostId>zzzz.oss-cn-shanghai.aliyuncs.com</HostId>
</Error>

  Key错了。正确的KEY是 test1536995822372.jpg  不能带?以后部分

com.aliyun.oss.OSSException: The specified key does not exist.
[ErrorCode]: NoSuchKey
[RequestId]: 5BA231E84031CABEAB41A444
[HostId]: imgadrms.oss-cn-shanghai.aliyuncs.com
[ResponseError]:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<RequestId>5BA231E84031CABEAB41A444</RequestId>
<HostId>imx.oss-cn-shanghai.aliyuncs.com</HostId>
<Key>test1536995822372.jpg?x-oss-process=image/rotate,90</Key>
</Error>

原文地址:https://www.cnblogs.com/nanahome/p/9676557.html