uploadAttachedMedia.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Created by Aliyun ApsaraVideo VoD.
  4. * User: https://www.aliyun.com/product/vod
  5. * API document: https://help.aliyun.com/document_detail/98467.html
  6. */
  7. require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'voduploadsdk' . DIRECTORY_SEPARATOR . 'Autoloader.php';
  8. date_default_timezone_set('PRC');
  9. // 测试上传本地辅助媒资文件
  10. function testUploadLocalAttachedMedia($accessKeyId, $accessKeySecret, $filePath)
  11. {
  12. try {
  13. $uploader = new AliyunVodUploader($accessKeyId, $accessKeySecret);
  14. $uploadAttachedRequest = new UploadAttachedMediaRequest($filePath, 'watermark',
  15. 'testUploadLocalAttachedMedia via PHP-SDK');
  16. //$uploadAttachedRequest->setCateId(1000009458);
  17. $res = $uploader->uploadLocalAttachedMedia($uploadAttachedRequest);
  18. print_r($res);
  19. } catch (Exception $e) {
  20. printf("testUploadLocalAttachedMedia Failed, ErrorMessage: %s\n", $e->getMessage());
  21. }
  22. }
  23. // 测试上传网络辅助媒资文件
  24. function testUploadWebAttachedMedia($accessKeyId, $accessKeySecret, $fileURL)
  25. {
  26. try {
  27. $uploader = new AliyunVodUploader($accessKeyId, $accessKeySecret);
  28. $uploadAttachedRequest = new UploadAttachedMediaRequest($fileURL, 'watermark',
  29. 'testUploadWebAttachedMedia via PHP-SDK');
  30. //$uploadAttachedRequest->setCateId(1000009458);
  31. $res = $uploader->uploadWebAttachedMedia($uploadAttachedRequest);
  32. print_r($res);
  33. } catch (Exception $e) {
  34. printf("testUploadWebAttachedMedia Failed, ErrorMessage: %s\n", $e->getMessage());
  35. }
  36. }
  37. #### 执行测试代码 ####
  38. $accessKeyId = '<AccessKeyId>';
  39. $accessKeySecret = '<AccessKeySecret>';
  40. $localFilePath = '/opt/image/test.png';
  41. //testUploadLocalAttachedMedia($accessKeyId, $accessKeySecret, $localFilePath);
  42. $webFileURL = 'http://vod-download.cn-shanghai.aliyuncs.com/retina/pic/20180208/496AE240-54AE-4CC8-8578-3EEC8F386E0B.gif';
  43. testUploadWebAttachedMedia($accessKeyId, $accessKeySecret, $webFileURL);