OSS圖片 數據處理持久化 JAVA實現

七牛及阿里雲OSS圖片旋轉問題html

上一篇文章我用了URL方式的圖片旋轉功能。但我須要的是一個持久化的結果。把旋轉後的圖片保存到OSS上,因此須要 數據持久化的操做。post

數據處理持久化

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/rotatespa

紅色部分不須要寫 style 中debug

 

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>code

 

  Key錯了。正確的KEY是 test1536995822372.jpg  不能帶?之後部分orm

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>xml

相關文章
相關標籤/搜索