edit-icon download-icon

Add media

Last Updated: Mar 28, 2018

Add media file to Media Files, and the user can specify workflow ID to trigger the workflow, which then processes the video file:

  1. package com.aliyun.mts;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.aliyuncs.DefaultAcsClient;
  4. import com.aliyuncs.exceptions.ClientException;
  5. import com.aliyuncs.exceptions.ServerException;
  6. import com.aliyuncs.mts.model.v20140618.AddMediaRequest;
  7. import com.aliyuncs.mts.model.v20140618.AddMediaResponse;
  8. import com.aliyuncs.profile.DefaultProfile;
  9. import org.apache.commons.lang.exception.ExceptionUtils;
  10. public class AddMedia {
  11. //Step 1 .set region:cn-hangzhou、cn-shenzhen、cn-shanghai、cn-beijing
  12. private static final String REGION = "cn-shenzhen";
  13. private static final String OSS_REGION = "oss-cn-shenzhen";
  14. private static final String mtsEndpoint = "mts." + REGION + ".aliyuncs.com";
  15. //Step 2.set accesskey & keySecret
  16. private static String accessKeyId = "";
  17. private static String accessKeySecret = "";
  18. private static DefaultAcsClient aliyunClient;
  19. static {
  20. try {
  21. DefaultProfile.addEndpoint(REGION, REGION, "Mts", mtsEndpoint);
  22. } catch (ClientException e) {
  23. System.out.print(ExceptionUtils.getStackTrace(e));
  24. System.exit(1);
  25. }
  26. aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile(REGION, accessKeyId, accessKeySecret));
  27. }
  28. public static void main(String[] args) throws ClientException {
  29. AddMediaRequest request = new AddMediaRequest();
  30. request.setFileURL("http://mtb-sz-in.oss-cn-shenzhen.aliyuncs.com/media/r180-ABC.mp4");
  31. request.setMediaWorkflowId("829bed0300994057a49e4f16de957e34");
  32. try {
  33. AddMediaResponse response = aliyunClient.getAcsResponse(request);
  34. System.out.println(JSONObject.toJSONString(response));
  35. } catch (ServerException e) {
  36. System.out.println("Code:" + e.getErrCode() + " Msg:" + e.getMessage());
  37. } catch (ClientException e) {
  38. System.out.println("Code:" + e.getErrCode() + " Msg:" + e.getMessage());
  39. }
  40. }
  41. }
Thank you! We've received your feedback.