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

Use the Alibaba Cloud OpenAPI Developer Portal to debug online.

import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import Credential, { Config } from '@alicloud/credentials';
const Client = require('@alicloud/ice20201109').default;
const { SubmitSnapshotJobRequestOutput, SubmitSnapshotJobRequestInput, SubmitSnapshotJobRequestTemplateConfig } = require('@alicloud/ice20201109');

// An Alibaba Cloud account AccessKey has full access permissions for all APIs. Use a Resource Access Management (RAM) user for API access or daily O&M.
// This example shows how to save the AccessKey ID and AccessKey secret in environment variables. For information about how to configure them, see: https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-node-js-access-credentials.

const cred = new Credential();
const iceClient = new Client(new $OpenApi.Config({
  credential: cred,
  endpoint: 'ice.cn-shanghai.aliyuncs.com'
}));

// To hard-code the AccessKey ID and AccessKey secret, use the following code. However, do not save the AccessKey ID and AccessKey secret in your project code. This prevents AccessKey leaks and protects all resources in your account.
// const iceClient = new Client(new $OpenApi.Config({
//   accessKeyId: '<yourAccessKeyId>',
//   accessKeySecret: '<yourAccessKeySecret>',
//   endpoint: 'ice.cn-shanghai.aliyuncs.com'
// }));

// Create a custom snapshot template.
var snapshotTemplateconfig = "{\"Type\":\"Normal\",\"FrameType\":\"normal\",\"Time\":0,\"Count\":10}";
iceClient.createCustomTemplate({
    name: "snapshotTestTemplate",
    templateConfig: snapshotTemplateconfig,
    type: 2
}).then(function (data) {
    console.log(data.body);
}, function (err) {
    console.log('Error:' + err);
});

// Submit a snapshot job.
iceClient.submitSnapshotJob({
    input: new SubmitSnapshotJobRequestInput({
        media: "6e9082b0507a71ed992190959850****",
        type: "Media"
    }),
    output: new SubmitSnapshotJobRequestOutput({
        media: "6e9082b0507a71ed992190959850****",
        type: "Media"
    }),
    templateConfig: new SubmitSnapshotJobRequestTemplateConfig({
        templateId: "8cf4c16c383f4a1f85b89c222a8f****"
    })
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// Query the snapshot job.
var jobId = "c899056c1e26442cb6c0b7676875****";
iceClient.getSnapshotJob({
    jobId: jobId
}).then(function (data) {
    console.log(data.body);
}, function (err) {
    console.log('Error:' + err);
});


// Get the list of snapshot jobs.
iceClient.listSnapshotJobs({
    pageSize: 5
}).then(function (data) {
    console.log(data.body);
}, function (err) {
    console.log('Error:' + err);
});

// Get the access URLs of the output images for the snapshot job.
var jobId = "c899056c1e26442cb6c0b7676875****";
iceClient.getSnapshotUrls({
    jobId: jobId,
    pageSize: 5
}).then(function (data) {
    console.log(data.body);
}, function (err) {
    console.log('Error:' + err);
});

Related API operations