OssClientWrapper implements InitializingBean, DisposableBean { public OSSClient getOssClient() { return ossClient; } OssClientWrapper(OssProperties ossProperties); @Override void destroy(); @Override void afterPropertiesSet(); Bucket createBucketIfNotExists(String bucketName); void setClinetConfig(ClientConfiguration clinetConfig); Optional<Bucket> getBucket(String bucketName, boolean createIfNotExist); List<Bucket> listBuckets(); ObjectOperation objectOperation(String key); ObjectOperation objectOperation(String bucketName, String key); String storeWithFileName(String bucketName, File file, ObjectMetadata meta); String store(String bucketName, File file, ObjectMetadata meta); String getUrl(boolean https, String bucketName, String key); PutObjectResult putObject(PutObjectRequest request); OSSClient getOssClient(); void deleteObject(String bucketName, String key);  }
@Test public void testUploadWithProcess() throws Exception { String text = "测试"; text = LangUtils.newString(Base64.encodeBase64(text.getBytes())); String styleType = "image/watermark,text_" + text; String targetImage = "test/test2.jpg"; String str = String.format("%s|sys/saveas,o_%s,b_%s", styleType, LangUtils.newString(Base64.encodeBase64(targetImage.getBytes())), LangUtils.newString(Base64.encodeBase64(bucketName.getBytes()))); ProcessObjectRequest por = new ProcessObjectRequest(bucketName, "test/test.jpg", str); this.wraper.getOssClient().processObject(por); }
@Test public void testWatermarkAction() throws Exception { WatermarkAction obj = new WatermarkAction(); obj.setBucketName(bucketName); obj.setSourceKey("test/test.jpg"); obj.setTargetKey("test/test2.jpg"); obj.setText("测试又测试"); obj.setFont(WatermarkFonts.FANGZHENGKAITI); obj.setSize(400); obj.setColor("FFFFFF"); obj.setLocation("center"); System.out.println("style: " + obj.toStyleWithName()); this.wraper.getOssClient().processObject(obj.buildRequest()); }
@Test public void testResizeAction() throws Exception { ResizeAction obj = new ResizeAction(); obj.setBucketName(bucketName); obj.setSourceKey("test/test.jpg"); obj.setTargetKey("test/test2.jpg"); ResizeProperties config = new ResizeProperties(); config.setWidth(200); obj.configBy(config); System.out.println("style: " + obj.toStyleWithName()); this.wraper.getOssClient().processObject(obj.buildRequest()); }