Snapshot jobs
Updated at:
By reading this article, you can learn the sample code for calling the OpenAPI to initiate and query the screenshot task of Smart Media Service through the server SDK.
Usage notes
Before you submit a snapshot job, you must create a snapshot template. Specify the TemplateId (snapshot template ID) when you submit the job. You can overwrite and reset the template parameters at submission time. After the job is processed, use the returned JobId (job ID) to query job details, list snapshot jobs, and obtain the access URLs for the snapshots.
Sample code
You can debug the API online in the Alibaba Cloud OpenAPI Developer Portal.
package com.aliyun.ice.sample;
import com.aliyun.ice20201109.Client;
import com.aliyun.ice20201109.models.*;
import com.aliyun.teaopenapi.models.Config;
public class Sample {
public static void main() throws Exception {
// An AccessKey of an Alibaba Cloud account has full access permissions for all APIs. Use a Resource Access Management (RAM) user for API calls or daily O&M.
// This example shows how to store the AccessKey ID and AccessKey secret in environment variables. For information about how to configure them, see https://help.aliyun.com/document_detail/378657.html
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config();
config.setCredential(credentialClient);
// If you want to hard-code the AccessKey ID and AccessKey secret, use the following code. However, do not store the AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey leak and compromise the security of all resources in your account.
// config.accessKeyId = <yourAccessKeyId>;
// config.accessKeySecret = <yourAccessKeySecret>;
config.endpoint = "ice.cn-shanghai.aliyuncs.com";
Client client = new Client(config);
// Create a snapshot template
String snapshotTemplateConfig = "{\"Type\":\"Normal\",\"FrameType\":\"normal\",\"Time\":0,\"Count\":10}";
CreateCustomTemplateRequest createCustomTemplateRequest = new CreateCustomTemplateRequest()
.setName("sdk_sample_snapshot_template")
.setType(2)
.setTemplateConfig(snapshotTemplateConfig);
CreateCustomTemplateResponse createCustomTemplateResponse = client.createCustomTemplate(createCustomTemplateRequest);
String templateId = createCustomTemplateResponse.getBody().getCustomTemplate().getTemplateId();
System.out.println("template id: " + templateId);
// Submit a snapshot job
SubmitSnapshotJobRequest submitSnapshotJobRequest = new SubmitSnapshotJobRequest()
.setName("sdk_sample_snapshot_job")
.setInput(new SubmitSnapshotJobRequest.SubmitSnapshotJobRequestInput()
.setType("Media")
.setMedia("3945e42d01823498****"))
.setOutput(new SubmitSnapshotJobRequest.SubmitSnapshotJobRequestOutput()
.setType("Media")
.setMedia("3945e42d01823498****"))
.setTemplateConfig(new SubmitSnapshotJobRequest.SubmitSnapshotJobRequestTemplateConfig()
.setTemplateId(templateId));
SubmitSnapshotJobResponse submitSnapshotJobResponse = client.submitSnapshotJob(submitSnapshotJobRequest);
String jobId = submitSnapshotJobResponse.getBody().getJobId();
System.out.println("job id: " + templateId);
// Query the details of the snapshot job
GetSnapshotJobRequest getSnapshotJobRequest = new GetSnapshotJobRequest()
.setJobId(jobId);
GetSnapshotJobResponse getSnapshotJobResponse = client.getSnapshotJob(getSnapshotJobRequest);
System.out.println("request id: " + getSnapshotJobResponse.getBody().getRequestId());
// Get the list of snapshot jobs
ListSnapshotJobsRequest listSnapshotJobsRequest = new ListSnapshotJobsRequest()
.setPageSize(5);
ListSnapshotJobsResponse listSnapshotJobsResponse = client.listSnapshotJobs(listSnapshotJobsRequest);
System.out.println("request id: " + listSnapshotJobsResponse.getBody().getRequestId());
// Get the access URLs of the output images for the snapshot job
GetSnapshotUrlsRequest getSnapshotUrlsRequest = new GetSnapshotUrlsRequest()
.setJobId("20b48fb04483915d4f2cd8ac****")
.setPageSize(5);
GetSnapshotUrlsResponse getSnapshotUrlsResponse = client.getSnapshotUrls(getSnapshotUrlsRequest);
System.out.println("request id: " + getSnapshotJobResponse.getBody().getRequestId());
}
} Related API operations
Is this page helpful?