ApsaraVideo VOD SDKは、メディアのアップロードにさまざまなAPI操作を提供します。 APIを呼び出して、メディアファイルをApsaraVideo VODにアップロードできます。 このトピックでは、ApsaraVideo VOD SDK for Javaを使用してAPI操作を呼び出してメディアファイルをアップロードできるシナリオとサンプルコードについて説明します。
シナリオ
このトピックでは、アップロード資格情報やアップロードURLを取得する操作など、API操作の呼び出し例のみを示します。 次の表に、API操作を呼び出してメディアファイルをアップロードできるシナリオを示します。
API 操作 | シナリオ |
| |
| |
|
前提条件
使用上の注意
この例では、AccessKeyペアを使用してクライアントインスタンスを初期化します。
この操作のリクエストおよびレスポンスパラメーターの詳細については、「OpenAPI Explorer」をご参照ください。 上部のナビゲーションバーで [APIドキュメント] をクリックすると、API操作に関連する情報が表示されます。
このトピックでは、一部の複雑なAPI操作のサンプルコードのみを示します。 他のAPI操作のサンプルコードを取得するには、次の操作を実行します。 「Alibaba Cloud OpenAPI Explorer」をご参照ください。左側のナビゲーションウィンドウで、サンプルコードを取得するAPI操作を見つけ、[パラメーター] タブで必要なパラメーターを指定します。 次に、[呼び出しの開始] をクリックします。 [SDKサンプルコード] タブで、サンプルコードを表示およびダウンロードする言語を選択します。
このトピックでは、ApsaraVideo VOD SDK for Java V1.0を使用してAPI操作を呼び出す方法について説明します。 ApsaraVideo VOD SDK for Java V2.0を使用してAPI操作を呼び出す場合、Alibaba Cloud OpenAPI Explorerでサンプルコードを取得するときにV2.0を指定します。
API呼び出しの例
オーディオまたはビデオファイルをアップロードするためのURLと資格情報の取得
CreateUploadVideo操作を呼び出して、オーディオまたはビデオファイルをアップロードするためのアップロードURLとアップロード資格情報を取得できます。
この操作の詳細については、CreateUploadVideoを参照してください。
サンプルコード:
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoRequest;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;
/**
*
* Sample code for obtaining a credential for uploading an audio or video file
*/
public class AudioOrVideoCreateUploadDemo {
/**
* Obtain the AccessKey information.
*/
public static DefaultAcsClient initVodClient() throws ClientException {
// The region in which ApsaraVideo VOD is activated.
String regionId = "cn-shanghai";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M.
// We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
/**
* Obtain an upload URL and an upload credential for uploading an audio or video file.
* @param client The client that sends a request.
* @return CreateUploadVideoResponse The fields contained in the response.
* @throws Exception
*/
public static CreateUploadVideoResponse createUploadVideo(DefaultAcsClient client) throws Exception {
CreateUploadVideoRequest request = new CreateUploadVideoRequest();
request.setTitle("this is a sample");
request.setFileName("filename.mp4");
// Optional. The user data that consists of user-defined parameters. Configure the user data if you need a callback URL and transparent data transmission.
//JSONObject userData = new JSONObject();
// The callback configurations in the user data.
// The callback settings for event notifications. If you specify callback settings, the specified callback settings take effect. Otherwise, the global callback settings take effect.
//JSONObject messageCallback = new JSONObject();
// The callback URL.
//messageCallback.put("CallbackURL", "http://192.168.0.1/16");
// The callback type. Default value: http.
//messageCallback.put("CallbackType", "http");
//userData.put("MessageCallback", messageCallback.toJSONString());
// The configurations of transparent data transmission in the user data.
// The user-defined extension parameter, which is transparently transferred during the callback.
//JSONObject extend = new JSONObject();
//extend.put("MyId", "user-defined-id");
//userData.put("Extend", extend.toJSONString());
//request.setUserData(userData.toJSONString());
return client.getAcsResponse(request);
}
/**
* Request example
*/
public static void main(String[] argv) throws ClientException {
try {
DefaultAcsClient client = initVodClient();
CreateUploadVideoResponse response = new CreateUploadVideoResponse();
response = createUploadVideo(client);
System.out.print("VideoId = " + response.getVideoId() + "\n");
System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
System.out.print("RequestId = " + response.getRequestId() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
}
}
オーディオまたはビデオファイルをアップロードするための資格情報を更新する
RefreshUploadVideo操作を呼び出して、オーディオまたはビデオファイルをアップロードするための資格情報を更新できます。
この操作の詳細については、RefreshUploadVideoを参照してください。
サンプルコード:
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoRequest;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse;
/**
*
* Sample code for updating the credential for uploading an audio or video file
*/
public class AudioOrVideoRefreshUploadDemo {
/**
* Obtain the AccessKey information.
*/
public static DefaultAcsClient initVodClient() throws ClientException {
// The region in which ApsaraVideo VOD is activated.
String regionId = "cn-shanghai";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M.
// We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
/**
* Update the credential for uploading an audio or video file.
* @param client The client that sends a request.
* @return RefreshUploadVideoResponse The fields contained in the response.
* @throws Exception
*/
public static RefreshUploadVideoResponse refreshUploadVideo(DefaultAcsClient client) throws Exception {
RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
// The ID of the audio file or video.
request.setVideoId("<VideoId>");
return client.getAcsResponse(request);
}
/**
* Request example
*/
public static void main(String[] argv) {
try {
DefaultAcsClient client = initVodClient();
RefreshUploadVideoResponse response = refreshUploadVideo(client);
System.out.print("VideoId = " + response.getVideoId() + "\n");
System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
System.out.print("RequestId = " + response.getRequestId() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
}
}
画像をアップロードするためのURLと資格情報の取得
CreateUploadImage操作を呼び出して、画像をアップロードするためのURLと資格情報を取得できます。
この操作の詳細については、CreateUploadImageを参照してください。
サンプルコード:
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.CreateUploadImageRequest;
import com.aliyuncs.vod.model.v20170321.CreateUploadImageResponse;
/**
* Sample code for obtaining a URL and a credential for uploading an image.
*
*/
public class ImageCreateUploadDemo {
/**
* Obtain the AccessKey information.
*/
public static DefaultAcsClient initVodClient() throws ClientException {
// The region in which ApsaraVideo VOD is activated.
String regionId = "cn-shanghai";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M.
// We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
/**
* Obtain a URL and a credential for uploading an image.
* @param client The client that sends a request.
* @return CreateUploadImageResponse The fields contained in the response.
* @throws Exception
*/
public static CreateUploadImageResponse createUploadImage(DefaultAcsClient client) throws Exception {
CreateUploadImageRequest request = new CreateUploadImageRequest();
// The image type.
request.setImageType("default");
// The file name extension of the image.
request.setImageExt("gif");
// The image title.
request.setTitle("this is a sample");
// Optional. The user data that consists of user-defined parameters. Configure the user data if you need a callback URL and transparent data transmission.
JSONObject userData = new JSONObject();
// The callback configurations in the user data.
// The callback settings for event notifications. If you specify callback settings, the specified callback settings take effect. Otherwise, the global callback settings take effect.
JSONObject messageCallback = new JSONObject();
// The callback URL.
messageCallback.put("CallbackURL", "http://192.168.0.0/16");
// The callback type. Default value: http.
messageCallback.put("CallbackType", "http");
userData.put("MessageCallback", messageCallback.toJSONString());
JSONObject extend = new JSONObject();
extend.put("MyId", "user-defined-id");
userData.put("Extend", extend.toJSONString());
request.setUserData(userData.toJSONString());
return client.getAcsResponse(request);
}
/**
* Request example
*/
public static void main(String[] argv) {
try {
DefaultAcsClient client = initVodClient();
CreateUploadImageResponse response = createUploadImage(client);
System.out.print("ImageId = " + response.getImageId() + "\n");
System.out.print("ImageURL = " + response.getImageURL() + "\n");
System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
System.out.print("RequestId = " + response.getRequestId() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
}
}
補助メディア資産をアップロードするためのURLと資格情報の取得
CreateUploadAttachedMedia操作を呼び出して、補助メディアアセットをアップロードするためのURLと資格情報を取得できます。
この操作の詳細については、CreateUploadAttachedMediaを参照してください。
サンプルコード:
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.CreateUploadAttachedMediaRequest;
import com.aliyuncs.vod.model.v20170321.CreateUploadAttachedMediaResponse;
/**
* Sample code for obtaining a URL and a credential for uploading an auxiliary media asset
*
*/
public class AttachedMediaCreateUploadDemo {
/**
* Obtain the AccessKey information.
*/
public static DefaultAcsClient initVodClient() throws ClientException {
// The region in which ApsaraVideo VOD is activated.
String regionId = "cn-shanghai";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M.
// We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
/**
* Obtain a URL and a credential for uploading an auxiliary media asset, such as a watermark or subtitle file.
* @param client The client that sends a request.
* @return CreateUploadAttachedMediaResponse The fields contained in the response.
* @throws Exception
*/
public static CreateUploadAttachedMediaResponse createUploadAttachedMedia(DefaultAcsClient client) throws Exception {
CreateUploadAttachedMediaRequest request = new CreateUploadAttachedMediaRequest();
// The business type.
request.setBusinessType("watermark");
// The file name extension.
request.setMediaExt("gif");
// The title.
request.setTitle("this is a sample");
// Optional. The user data that consists of user-defined parameters. Configure the user data if you need a callback URL and transparent data transmission.
JSONObject userData = new JSONObject();
// The callback configurations in the user data.
// The callback settings for event notifications. If you specify callback settings, the specified callback settings take effect. Otherwise, the global callback settings take effect.
JSONObject messageCallback = new JSONObject();
// The callback URL.
messageCallback.put("CallbackURL", "http://192.168.0.0/16");
// The callback type. Default value: http.
messageCallback.put("CallbackType", "http");
userData.put("MessageCallback", messageCallback.toJSONString());
JSONObject extend = new JSONObject();
extend.put("MyId", "user-defined-id");
userData.put("Extend", extend.toJSONString());
request.setUserData(userData.toJSONString());
return client.getAcsResponse(request);
}
/**
* Request example
*/
public static void main(String[] argv) {
try {
DefaultAcsClient client = initVodClient();
CreateUploadAttachedMediaResponse response = createUploadAttachedMedia(client);
System.out.print("mediaId = " + response.getMediaId() + "\n");
System.out.print("mediaURL = " + response.getMediaURL() + "\n");
System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
System.out.print("RequestId = " + response.getRequestId() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
}
}
URLに基づいて一度に複数のメディアファイルをアップロードする
UploadMediaByURL操作を呼び出して、URLに基づいて一度に複数のメディアファイルをアップロードできます。
この操作の詳細については、UploadMediaByURLを参照してください。
サンプルコード:
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.UploadMediaByURLRequest;
import com.aliyuncs.vod.model.v20170321.UploadMediaByURLResponse;
import java.net.URLEncoder;
/**
* Sample code for uploading media files at a time based on URLs
*
*/
public class AudioOrVideoUploadByUrl {
/**
* Obtain the AccessKey information.
*/
public static DefaultAcsClient initVodClient() throws ClientException {
// The region in which ApsaraVideo VOD is activated.
String regionId = "cn-shanghai";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M.
// We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
/**
* Upload media files at a time based on URLs.
*
* @param client The client that sends a request.
* @return UploadMediaByURLResponse The fields contained in the response.
* @throws Exception
*/
public static UploadMediaByURLResponse uploadMediaByURL(DefaultAcsClient client) throws Exception {
UploadMediaByURLRequest request = new UploadMediaByURLRequest();
String url = "http://video_01.mp4";
String encodeUrl = URLEncoder.encode(url, "UTF-8");
// The URLs of source files.
request.setUploadURLs(encodeUrl);
// The metadata of the video that you want to upload.
JSONObject uploadMetadata = new JSONObject();
// The URLs of the source files that you want to upload. The URL must be included in the value of the UploadURLs parameter.
uploadMetadata.put("SourceUrl", encodeUrl);
// The video title.
uploadMetadata.put("Title", "upload by url sample");
JSONArray uploadMetadataList = new JSONArray();
uploadMetadataList.add(uploadMetadata);
request.setUploadMetadatas(uploadMetadataList.toJSONString());
// Optional. The user data that consists of user-defined parameters. Configure the user data if you need a callback URL and transparent data transmission.
JSONObject userData = new JSONObject();
// The callback configurations in the user data.
// The callback settings for event notifications. If you specify callback settings, the specified callback settings take effect. Otherwise, the global callback settings take effect.
JSONObject messageCallback = new JSONObject();
// The callback URL.
messageCallback.put("CallbackURL", "http://192.168.0.0/16");
// The callback type. Default value: http.
messageCallback.put("CallbackType", "http");
userData.put("MessageCallback", messageCallback.toJSONString());
JSONObject extend = new JSONObject();
extend.put("MyId", "user-defined-id");
userData.put("Extend", extend.toJSONString());
request.setUserData(userData.toJSONString());
return client.getAcsResponse(request);
}
/**
* Request example
*/
public static void main(String[] argv) {
try {
DefaultAcsClient client = initVodClient();
UploadMediaByURLResponse response = uploadMediaByURL(client);
System.out.print("UploadJobs = " + JSON.toJSONString(response.getUploadJobs()) + "\n");
System.out.print("RequestId = " + response.getRequestId() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
}
}
メディア資産の登録
RegisterMedia操作を呼び出して、メディアアセットを登録できます。
この操作の詳細については、RegisterMediaを参照してください。
サンプルコード:
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.RegisterMediaRequest;
import com.aliyuncs.vod.model.v20170321.RegisterMediaResponse;
/**
* Sample code for registering media assets
*
*/
public class MediaRegisterDemo {
/**
* Obtain the AccessKey information.
*/
public static DefaultAcsClient initVodClient() throws ClientException {
// The region in which ApsaraVideo VOD is activated.
String regionId = "cn-shanghai";
// The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M.
// We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
/**
* Register media assets.
* @param client The client that sends a request.
* @return RegisterMediaResponse The fields contained in the response.
* @throws Exception
*/
public static RegisterMediaResponse registerMedia(DefaultAcsClient client) throws Exception {
RegisterMediaRequest request = new RegisterMediaRequest();
JSONArray metaDataArray = new JSONArray();
JSONObject metaData = new JSONObject();
// The title.
metaData.put("Title", "this is a sample");
// The URL of the source file. The file name in the URL must be unique. If the file name is repeatedly registered, the unique media ID that is associated with the file name is returned.
metaData.put("FileURL", "https://192.168.0.0/16.oss-cn-shanghai.aliyuncs.com/vod_sample.mp4");
// The metadata of the media asset to be registered.
metaDataArray.add((metaData));
request.setRegisterMetadatas(metaDataArray.toJSONString());
return client.getAcsResponse(request);
}
/**
* Request example
*/
public static void main(String[] argv) {
try {
DefaultAcsClient client = initVodClient();
RegisterMediaResponse response = registerMedia(client);
if (response.getFailedFileURLs() != null && response.getFailedFileURLs().size() > 0) {
for (String fileURL : response.getFailedFileURLs()) {
System.out.print("FailedFileURL = " + fileURL + "\n");
}
}
if (response.getRegisteredMediaList() != null && response.getRegisteredMediaList().size() > 0) {
for (RegisterMediaResponse.RegisteredMedia registeredMedia : response.getRegisteredMediaList()) {
System.out.print("MediaId = " + registeredMedia.getMediaId());
System.out.print("FileURL = " + registeredMedia.getFileURL());
System.out.print("NewRegister = " + registeredMedia.getNewRegister());
System.out.print("RequestId = " + response.getRequestId() + "\n");
}
}
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
}
}
URLベースのアップロードジョブに関する情報の照会
GetURLUploadInfos操作を呼び出して、URLベースのアップロードジョブに関する情報を照会できます。
この操作の詳細については、GetURLUploadInfosを参照してください。
サンプルコード:
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetURLUploadInfosRequest;
import com.aliyuncs.vod.model.v20170321.GetURLUploadInfosResponse;
import org.apache.commons.lang3.StringUtils;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
/**
* Query the information about URL-based upload jobs.
*/
public class URLUploadInfosGetDemo {
/**
* Obtain the AccessKey information.
*/
public static DefaultAcsClient initVodClient() throws ClientException {
// The region in which ApsaraVideo VOD is activated.
String regionId = "cn-shanghai";
// The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M.
// We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
/**
* Query information about URL-based upload jobs.
*
* @param client The client that sends a request.
* @return GetURLUploadInfosResponse The fields contained in the response.
* @throws Exception
*/
public static GetURLUploadInfosResponse getURLUploadInfos(DefaultAcsClient client) throws Exception {
GetURLUploadInfosRequest request = new GetURLUploadInfosRequest();
// The URLs of video source files. The URLs must be encoded.
String[] urls = {
"http://exampleBucket****.cn-shanghai.aliyuncs.com/video_01.mp4",
"http://exampleBucket****.cn-shanghai.aliyuncs.com/video_02.flv"
};
List<String> encodeUrlList = new ArrayList<String>();
for (String url : urls) {
encodeUrlList.add(URLEncoder.encode(url, "UTF-8"));
}
request.setUploadURLs(StringUtils.join(encodeUrlList, ','));
// The job IDs. You can obtain the job IDs from the PlayInfo parameter returned by the GetPlayInfo operation.
//request.setJobIds("exampleID1,exampleID2");
return client.getAcsResponse(request);
}
/**
* Request example
*/
public static void main(String[] argv) {
try {
DefaultAcsClient client = initVodClient();
GetURLUploadInfosResponse response = getURLUploadInfos(client);
System.out.print("URLUploadInfoList = " + response.getURLUploadInfoList() + "\n");
System.out.print("RequestId = " + response.getRequestId() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
}
}