diff --git a/src/main/java/com/aliyun/oss/OSS.java b/src/main/java/com/aliyun/oss/OSS.java index 228b5471..c94c630a 100644 --- a/src/main/java/com/aliyun/oss/OSS.java +++ b/src/main/java/com/aliyun/oss/OSS.java @@ -4185,7 +4185,7 @@ public String generateRtmpUri(GenerateRtmpUriRequest generatePushflowUrlRequest) * must be closed by the calller to release connection via calling * getResponse().getContent().close(). *

- * + * * @param processObjectRequest * A {@link ProcessObjectRequest} instance that specifies the * bucket name, the object key and the process (such as @@ -5101,4 +5101,27 @@ public UdfApplicationLog getUdfApplicationLog(GetUdfApplicationLogRequest getUdf * If any errors occurred in OSS while processing the request. */ VoidResult closeMetaQuery(String bucketName) throws OSSException, ClientException; + + /** + * Apply async process on the specified image file. + *

+ * The supported async process includes resize, rotate, crop, watermark, format, + * udf, customized style, etc. The {@link GenericResult} instance returned + * must be closed by the calller to release connection via calling + * getResponse().getContent().close(). + *

+ * + * @param asyncProcessObjectRequest + * A {@link AsyncProcessObjectRequest} instance that specifies the + * bucket name, the object key and the process (such as + * video/convert,f_mp4,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1) + * @return A {@link AsyncProcessObjectResult} instance which must be closed after the + * usage by the caller. + * @throws OSSException + * If any errors are encountered in the client while making the + * request or handling the response. + * @throws ClientException + * If any errors occurred in OSS while processing the request. + */ + public AsyncProcessObjectResult asyncProcessObject(AsyncProcessObjectRequest asyncProcessObjectRequest) throws OSSException, ClientException; } diff --git a/src/main/java/com/aliyun/oss/OSSClient.java b/src/main/java/com/aliyun/oss/OSSClient.java index 8b995acb..f2b2db4c 100644 --- a/src/main/java/com/aliyun/oss/OSSClient.java +++ b/src/main/java/com/aliyun/oss/OSSClient.java @@ -1957,6 +1957,11 @@ public VoidResult closeMetaQuery(String bucketName) throws OSSException, ClientE return this.bucketOperation.closeMetaQuery(new GenericRequest(bucketName)); } + @Override + public AsyncProcessObjectResult asyncProcessObject(AsyncProcessObjectRequest asyncProcessObjectRequest) throws OSSException, ClientException { + return this.objectOperation.asyncProcessObject(asyncProcessObjectRequest); + } + @Override public void shutdown() { try { diff --git a/src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java b/src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java index 9ede985b..f5ab1b53 100644 --- a/src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java +++ b/src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java @@ -100,6 +100,7 @@ public final class RequestMarshallers { public static final PutBucketTransferAccelerationRequestMarshaller putBucketTransferAccelerationRequestMarshaller = new PutBucketTransferAccelerationRequestMarshaller(); public static final PutBucketAccessMonitorRequestMarshaller putBucketAccessMonitorRequestMarshaller = new PutBucketAccessMonitorRequestMarshaller(); public static final DoMetaQueryRequestMarshaller doMetaQueryRequestMarshaller = new DoMetaQueryRequestMarshaller(); + public static final AsyncProcessObjectRequestMarshaller asyncProcessObjectRequestMarshaller = new AsyncProcessObjectRequestMarshaller(); public interface RequestMarshaller extends Marshaller { @@ -1863,6 +1864,26 @@ public byte[] marshall(DoMetaQueryRequest input) { } } + public static final class AsyncProcessObjectRequestMarshaller implements RequestMarshaller2 { + + @Override + public byte[] marshall(AsyncProcessObjectRequest request) { + StringBuffer processBody = new StringBuffer(); + + processBody.append(RequestParameters.X_OSS_ASYNC_PROCESS); + processBody.append("=" + request.getProcess()); + + byte[] rawData = null; + try { + rawData = processBody.toString().getBytes(DEFAULT_CHARSET_NAME); + } catch (UnsupportedEncodingException e) { + throw new ClientException("Unsupported encoding " + e.getMessage(), e); + } + return rawData; + } + + } + private static enum EscapedChar { // "\r" RETURN(" "), diff --git a/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java b/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java index ad2a66cb..113818a8 100644 --- a/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java +++ b/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java @@ -1281,6 +1281,36 @@ private static void populateGetObjectRequestHeaders(GetObjectRequest getObjectRe populateTrafficLimitHeader(headers, getObjectRequest.getTrafficLimit()); } + public AsyncProcessObjectResult asyncProcessObject(AsyncProcessObjectRequest asyncProcessObjectRequest) throws OSSException, ClientException { + + assertParameterNotNull(asyncProcessObjectRequest, "asyncProcessObjectRequest"); + + String bucketName = asyncProcessObjectRequest.getBucketName(); + String key = asyncProcessObjectRequest.getKey(); + String process = asyncProcessObjectRequest.getProcess(); + + assertParameterNotNull(bucketName, "bucketName"); + ensureBucketNameValid(bucketName); + assertParameterNotNull(key, "key"); + ensureObjectKeyValid(key); + assertStringNotNullOrEmpty(process, "process"); + + Map params = new HashMap(); + params.put(RequestParameters.X_OSS_ASYNC_PROCESS, null); + + Map headers = new HashMap(); + populateRequestPayerHeader(headers, asyncProcessObjectRequest.getRequestPayer()); + + byte[] rawContent = asyncProcessObjectRequestMarshaller.marshall(asyncProcessObjectRequest); + + RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint(asyncProcessObjectRequest)) + .setMethod(HttpMethod.POST).setBucket(bucketName).setKey(key).setHeaders(headers).setParameters(params) + .setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent)) + .setOriginalRequest(asyncProcessObjectRequest).build(); + + return doOperation(request, ResponseParsers.asyncProcessObjectResponseParser, bucketName, key, true); + } + private static void addDeleteObjectsRequiredHeaders(Map headers, byte[] rawContent) { headers.put(HttpHeaders.CONTENT_LENGTH, String.valueOf(rawContent.length)); diff --git a/src/main/java/com/aliyun/oss/internal/RequestParameters.java b/src/main/java/com/aliyun/oss/internal/RequestParameters.java index e865d747..6df96971 100644 --- a/src/main/java/com/aliyun/oss/internal/RequestParameters.java +++ b/src/main/java/com/aliyun/oss/internal/RequestParameters.java @@ -156,5 +156,6 @@ public final class RequestParameters { public static final String ACCESS_MONITOR = "accessmonitor"; public static final String SUBRESOURCE_REGION_LIST = "regionList"; + public static final String X_OSS_ASYNC_PROCESS = "x-oss-async-process"; } diff --git a/src/main/java/com/aliyun/oss/internal/ResponseParsers.java b/src/main/java/com/aliyun/oss/internal/ResponseParsers.java index ce5bc5c4..79e951cf 100644 --- a/src/main/java/com/aliyun/oss/internal/ResponseParsers.java +++ b/src/main/java/com/aliyun/oss/internal/ResponseParsers.java @@ -24,6 +24,7 @@ import static com.aliyun.oss.internal.OSSUtils.safeCloseResponse; import static com.aliyun.oss.internal.OSSUtils.trimQuotes; +import java.io.IOException; import java.io.InputStream; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -37,8 +38,11 @@ import java.util.Map; import java.util.zip.CheckedInputStream; +import com.aliyun.oss.common.utils.IOUtils; import com.aliyun.oss.internal.model.OSSErrorResult; import com.aliyun.oss.model.*; +import org.codehaus.jettison.json.JSONException; +import org.codehaus.jettison.json.JSONObject; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.input.JDOMParseException; @@ -141,6 +145,7 @@ public final class ResponseParsers { public static final GetBucketAccessMonitorResponseParser getBucketAccessMonitorResponseParser = new GetBucketAccessMonitorResponseParser(); public static final GetMetaQueryStatusResponseParser getMetaQueryStatusResponseParser = new GetMetaQueryStatusResponseParser(); public static final DoMetaQueryResponseParser doMetaQueryResponseParser = new DoMetaQueryResponseParser(); + public static final AsyncProcessObjectResponseParser asyncProcessObjectResponseParser = new AsyncProcessObjectResponseParser(); public static Long parseLongWithDefault(String defaultValue){ if(defaultValue == null || "".equals(defaultValue)){ @@ -4157,4 +4162,43 @@ private DoMetaQueryResult parseDoMetaQueryResult(InputStream inputStream) throws } } } + + public static final class AsyncProcessObjectResponseParser implements ResponseParser { + + @Override + public AsyncProcessObjectResult parse(ResponseMessage response) throws ResponseParseException { + AsyncProcessObjectResult result = parseAsyncProcessObject(response.getContent()); + setResultParameter(result, response); + return result; + } + + private AsyncProcessObjectResult parseAsyncProcessObject(InputStream inputStream) throws ResponseParseException { + AsyncProcessObjectResult asyncProcessObjectResult = new AsyncProcessObjectResult(); + if (inputStream == null) { + return asyncProcessObjectResult; + } + + try { + String jsonStr = null; + try { + jsonStr = IOUtils.readStreamAsString(inputStream, "UTF-8"); + JSONObject jsonObject = new JSONObject(jsonStr); + asyncProcessObjectResult.setAsyncRequestId(jsonObject.getString("RequestId")); + asyncProcessObjectResult.setEventId(jsonObject.getString("EventId")); + asyncProcessObjectResult.setTaskId(jsonObject.getString("TaskId")); + } catch (IOException e) { + throw new ResponseParseException(e.getMessage(), e); + } catch (JSONException e) { + throw new ResponseParseException(e.getMessage(), e); + } finally { + if (inputStream != null){ + inputStream.close(); + } + } + return asyncProcessObjectResult; + } catch (Exception e) { + throw new ResponseParseException(e.getMessage(), e); + } + } + } } diff --git a/src/main/java/com/aliyun/oss/internal/SignParameters.java b/src/main/java/com/aliyun/oss/internal/SignParameters.java index 8f82f1ea..9d861439 100644 --- a/src/main/java/com/aliyun/oss/internal/SignParameters.java +++ b/src/main/java/com/aliyun/oss/internal/SignParameters.java @@ -43,6 +43,6 @@ public class SignParameters { SUBRESOURCE_WORM_ID, SUBRESOURCE_WORM_EXTEND, SUBRESOURCE_CALLBACK, SUBRESOURCE_CALLBACK_VAR, SUBRESOURCE_DIR, SUBRESOURCE_RENAME, SUBRESOURCE_DIR_DELETE, SUBRESOURCE_TRANSFER_ACCELERATION, X_OSS_AC_SOURCE_IP, X_OSS_AC_SUBNET_MASK, X_OSS_AC_VPC_ID, X_OSS_AC_FORWARD_ALLOW, META_QUERY, SUBRESOURCE_RESOURCE_GROUP, - SUBRESOURCE_REGION_LIST}); + SUBRESOURCE_REGION_LIST, X_OSS_ASYNC_PROCESS}); } diff --git a/src/main/java/com/aliyun/oss/model/AsyncProcessObjectRequest.java b/src/main/java/com/aliyun/oss/model/AsyncProcessObjectRequest.java new file mode 100644 index 00000000..e9955ff3 --- /dev/null +++ b/src/main/java/com/aliyun/oss/model/AsyncProcessObjectRequest.java @@ -0,0 +1,25 @@ +package com.aliyun.oss.model; + + +public class AsyncProcessObjectRequest extends GenericRequest { + + public AsyncProcessObjectRequest(String bucketName, String key, String process) { + super(bucketName, key); + this.process = process; + } + + public String getProcess() { + return process; + } + + public void setProcess(String process) { + this.process = process; + } + + public AsyncProcessObjectRequest withProcess(String process) { + this.process = process; + return this; + } + + private String process; +} diff --git a/src/main/java/com/aliyun/oss/model/AsyncProcessObjectResult.java b/src/main/java/com/aliyun/oss/model/AsyncProcessObjectResult.java new file mode 100644 index 00000000..241fb182 --- /dev/null +++ b/src/main/java/com/aliyun/oss/model/AsyncProcessObjectResult.java @@ -0,0 +1,32 @@ +package com.aliyun.oss.model; + +public class AsyncProcessObjectResult extends GenericResult { + + private String asyncRequestId; + private String eventId; + private String taskId; + + public String getAsyncRequestId() { + return asyncRequestId; + } + + public void setAsyncRequestId(String asyncRequestId) { + this.asyncRequestId = asyncRequestId; + } + + public String getEventId() { + return eventId; + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } +} diff --git a/src/samples/AsyncProcessObjectSample.java b/src/samples/AsyncProcessObjectSample.java new file mode 100644 index 00000000..058af657 --- /dev/null +++ b/src/samples/AsyncProcessObjectSample.java @@ -0,0 +1,52 @@ +package samples; + +import com.aliyun.oss.common.utils.BinaryUtil; +import com.aliyun.oss.model.*; + +public class AsyncProcessObjectSample { + private static String endpoint = ""; + private static String accessKeyId = ""; + private static String accessKeySecret = ""; + private static String bucketName = ""; + private static final String saveAsKey = ""; + private static final String key = ""; + + public static void main(String[] args) { + /* + * Constructs a client instance with your account for accessing OSS + */ + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + try { + StringBuilder styleBuilder = new StringBuilder(); + styleBuilder.append("video/convert,f_mp4,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1"); // resize + styleBuilder.append("|sys/saveas,"); + styleBuilder.append("o_" + BinaryUtil.toBase64String(saveAsKey.getBytes()).replaceAll("=", "")); + styleBuilder.append(","); + styleBuilder.append("b_" + BinaryUtil.toBase64String(bucketName.getBytes()).replaceAll("=", "")); + + AsyncProcessObjectRequest request = new AsyncProcessObjectRequest(bucketName, key, styleBuilder.toString()); + + AsyncProcessObjectResult asyncProcessObject = ossClient.asyncProcessObject(request); + System.out.println(asyncProcessObject.getAsyncRequestId()); + System.out.println(asyncProcessObject.getEventId()); + System.out.println(asyncProcessObject.getTaskId()); + } catch (OSSException oe) { + System.out.println("Caught an OSSException, which means your request made it to OSS, " + + "but was rejected with an error response for some reason."); + System.out.println("Error Message: " + oe.getMessage()); + System.out.println("Error Code: " + oe.getErrorCode()); + System.out.println("Request ID: " + oe.getRequestId()); + System.out.println("Host ID: " + oe.getHostId()); + } catch (ClientException ce) { + System.out.println("Caught an ClientException, which means the client encountered " + + "a serious internal problem while trying to communicate with OSS, " + + "such as not being able to access the network."); + System.out.println("Error Message: " + ce.getMessage()); + } finally { + /* + * Do not forget to shut down the client finally to release all allocated resources. + */ + ossClient.shutdown(); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/aliyun/oss/common/parser/RequestMarshallersTest.java b/src/test/java/com/aliyun/oss/common/parser/RequestMarshallersTest.java index d79d8e84..b53aeef6 100644 --- a/src/test/java/com/aliyun/oss/common/parser/RequestMarshallersTest.java +++ b/src/test/java/com/aliyun/oss/common/parser/RequestMarshallersTest.java @@ -6,6 +6,7 @@ import com.aliyun.oss.OSSException; import com.aliyun.oss.common.comm.io.FixedLengthInputStream; +import com.aliyun.oss.common.utils.BinaryUtil; import com.aliyun.oss.common.utils.DateUtil; import com.aliyun.oss.model.*; import junit.framework.Assert; @@ -1413,4 +1414,27 @@ public void testPutLifeCycleRequestMarshaller() { Assert.assertEquals("key2", root.getChild("Rule").getChild("Filter").getChildren("Not").get(1).getChild("Tag").getChildText("Key")); Assert.assertEquals("value2", root.getChild("Rule").getChild("Filter").getChildren("Not").get(1).getChild("Tag").getChildText("Value")); } + + @Test + public void testAsyncProcessObjectRequestMarshaller() { + String saveAsKey = "outobjprefix.mp4"; + String originalVideo = "test-video.mp4/example.mp4"; + String bucketName = "example-bucket"; + StringBuilder styleBuilder = new StringBuilder(); + styleBuilder.append("test-video.mp4/convert,f_mp4,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1"); // resize + styleBuilder.append("|sys/saveas,"); + styleBuilder.append("o_" + BinaryUtil.toBase64String(saveAsKey.getBytes()).replaceAll("=", "")); + styleBuilder.append(","); + styleBuilder.append("b_" + BinaryUtil.toBase64String(bucketName.getBytes()).replaceAll("=", "")); + AsyncProcessObjectRequest request = new AsyncProcessObjectRequest(bucketName, originalVideo, styleBuilder.toString()); + + byte[] data = asyncProcessObjectRequestMarshaller.marshall(request); + + String returnData = new String(data); + + String style = styleBuilder.toString(); + + Assert.assertTrue(returnData.equals("x-oss-async-process="+style.replaceAll("=",""))); + } + } diff --git a/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java b/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java index ae594d59..5975c6dd 100644 --- a/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java +++ b/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java @@ -5140,4 +5140,49 @@ public void testParseListVersionsWithRestoreInfo() { Assert.assertEquals("object-with-special-restore", result.getVersionSummaries().get(0).getKey()); Assert.assertEquals("ongoing-request=\"true\"", result.getVersionSummaries().get(0).getRestoreInfo()); } + + @Test + public void testParseAsyncPorcessObject() { + InputStream instream = null; + String respBody; + + respBody = "{\"EventId\":\"3D7-1XxFtV2t3VtcOn2CXqI2ldsMN3i\",\"RequestId\":\"8DF65942-D483-5E7E-BC1A-B25C617A9C32\",\"TaskId\":\"MediaConvert-d2280366-cd33-48f7-90c6-a0dab65bed63\"}"; + try { + instream = new ByteArrayInputStream(respBody.getBytes("utf-8")); + } catch (UnsupportedEncodingException e) { + Assert.fail("UnsupportedEncodingException"); + } + + AsyncProcessObjectResult result = null; + try { + + ResponseMessage response = new ResponseMessage(null); + response.setContent(instream); + ResponseParsers.AsyncProcessObjectResponseParser parser = new ResponseParsers.AsyncProcessObjectResponseParser(); + result = parser.parse(response); + } catch (Exception e) { + Assert.assertTrue(false); + } + Assert.assertEquals("8DF65942-D483-5E7E-BC1A-B25C617A9C32", result.getAsyncRequestId()); + Assert.assertEquals("3D7-1XxFtV2t3VtcOn2CXqI2ldsMN3i", result.getEventId()); + Assert.assertEquals("MediaConvert-d2280366-cd33-48f7-90c6-a0dab65bed63", result.getTaskId()); + + // 测试如果返回为空字符串,应该报JSONObject错误 + respBody = ""; + try { + instream = new ByteArrayInputStream(respBody.getBytes("utf-8")); + } catch (UnsupportedEncodingException e) { + Assert.fail("UnsupportedEncodingException"); + } + + try { + + ResponseMessage response = new ResponseMessage(null); + response.setContent(instream); + ResponseParsers.AsyncProcessObjectResponseParser parser = new ResponseParsers.AsyncProcessObjectResponseParser(); + result = parser.parse(response); + } catch (Exception e) { + Assert.assertEquals("A JSONObject text must begin with '{' at character 0 of ", e.getMessage()); + } + } } diff --git a/src/test/java/com/aliyun/oss/integrationtests/AsyncProcessObjectTest.java b/src/test/java/com/aliyun/oss/integrationtests/AsyncProcessObjectTest.java new file mode 100644 index 00000000..8e86e201 --- /dev/null +++ b/src/test/java/com/aliyun/oss/integrationtests/AsyncProcessObjectTest.java @@ -0,0 +1,92 @@ +package com.aliyun.oss.integrationtests; + +import com.aliyun.oss.ClientConfiguration; +import com.aliyun.oss.OSSClient; +import com.aliyun.oss.OSSException; +import com.aliyun.oss.common.auth.Credentials; +import com.aliyun.oss.common.auth.DefaultCredentialProvider; +import com.aliyun.oss.common.auth.DefaultCredentials; +import com.aliyun.oss.common.utils.BinaryUtil; +import com.aliyun.oss.model.*; +import com.aliyun.oss.utils.ResourceUtils; +import junit.framework.Assert; +import org.junit.Test; +import java.io.File; + +import static com.aliyun.oss.integrationtests.TestUtils.waitForCacheExpiration; + +public class AsyncProcessObjectTest extends TestBase { + private static StringBuilder styleBuilder = new StringBuilder(); + private static final String saveAsKey = "out-test-video"; + private static final String key = "oss/test-video.mp4"; + private static final String endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; + private static final String bucketName = "examplebucket-zxl-test"; + + @Test + public void testSetBucketVersioning() throws Exception{ + OSSClient ossClient = null; +// final String bucketName = super.bucketName + "-async-process-object"; + try { + + // create client + ClientConfiguration conf = new ClientConfiguration().setSupportCname(false); + Credentials credentials = new DefaultCredentials(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET); + ossClient = new OSSClient(endpoint, new DefaultCredentialProvider(credentials), conf); + + // 创建固定在杭州的bucket + ossClient.createBucket(bucketName); + waitForCacheExpiration(2); + + File file = new File(ResourceUtils.getTestFilename(key)); + + // 上传原视频到oss + ossClient.putObject(bucketName, key, file); + + // 设置process + styleBuilder.append("video/convert,f_mp4,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1"); // resize + styleBuilder.append("|sys/saveas,"); + styleBuilder.append("o_" + BinaryUtil.toBase64String(saveAsKey.getBytes()).replaceAll("=", "")); + styleBuilder.append(","); + styleBuilder.append("b_" + BinaryUtil.toBase64String(bucketName.getBytes()).replaceAll("=", "")); + + AsyncProcessObjectRequest request = new AsyncProcessObjectRequest(bucketName, key, styleBuilder.toString()); + + // 调用asyncProcessObject + AsyncProcessObjectResult asyncProcessObject = ossClient.asyncProcessObject(request); + + // 如果开启了imm,并且创建了一个imm的project,然后绑定了project和bucket,既开始进入如下正常测试流程 + Assert.assertEquals(asyncProcessObject.getRequestId().length(), REQUEST_ID_LEN); + Assert.assertNotNull(asyncProcessObject.getEventId()); + Assert.assertNotNull(asyncProcessObject.getAsyncRequestId()); + Assert.assertNotNull(asyncProcessObject.getTaskId()); + + // 睡眠一段时间,等待异步视频处理完成。先根据视频大小/1m,然后再加5秒 + Thread.sleep((file.length() / 1000) + 5000); + + Assert.assertTrue(ossClient.doesObjectExist(bucketName, saveAsKey+".mp4")); + + // 删除视频文件和处理后的文件 + VoidResult delKey = ossClient.deleteObject(bucketName, key); + Assert.assertEquals(delKey.getResponse().getStatusCode(), 204); + VoidResult delSaveKey = ossClient.deleteObject(bucketName, saveAsKey+".mp4"); + Assert.assertEquals(delSaveKey.getResponse().getStatusCode(), 204); + + } catch (OSSException e) { + e.printStackTrace(); + // 如果没有开启imm,异步流程,暂时报如下错误 + Assert.assertEquals("operation not support post: video/convert", e.getErrorMessage()); + + } finally { + // 先删除文件,再删除bucket + VoidResult delKey = ossClient.deleteObject(bucketName, key); + Assert.assertEquals(delKey.getResponse().getStatusCode(), 204); + VoidResult delBucket = ossClient.deleteBucket(bucketName); + Assert.assertEquals(delBucket.getResponse().getStatusCode(), 204); + + if (ossClient != null) { + ossClient.shutdown(); + } + } + } + +} diff --git a/src/test/java/com/aliyun/oss/integrationtests/ImageProcessTest.java b/src/test/java/com/aliyun/oss/integrationtests/ImageProcessTest.java index 1fcf0702..1eec4795 100644 --- a/src/test/java/com/aliyun/oss/integrationtests/ImageProcessTest.java +++ b/src/test/java/com/aliyun/oss/integrationtests/ImageProcessTest.java @@ -25,6 +25,9 @@ import java.net.URL; import java.util.Date; +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.model.*; import junit.framework.Assert; import org.codehaus.jettison.json.JSONException; diff --git a/src/test/resources/oss/test-video.mp4 b/src/test/resources/oss/test-video.mp4 new file mode 100644 index 00000000..9da29367 Binary files /dev/null and b/src/test/resources/oss/test-video.mp4 differ