Geen omschrijving

put_bucketEvent.php 930B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Config;
  5. use Qiniu\Storage\BucketManager;
  6. // 控制台获取密钥:https://portal.qiniu.com/user/key
  7. $accessKey = getenv('QINIU_ACCESS_KEY');
  8. $secretKey = getenv('QINIU_SECRET_KEY');
  9. $auth = new Auth($accessKey, $secretKey);
  10. $config = new Config();
  11. $bucketManager = new BucketManager($auth, $config);
  12. // 增加 bucket 事件通知规则
  13. // 参考文档:https://developer.qiniu.com/kodo/manual/6095/event-notification
  14. $bucket = getenv('QINIU_TEST_BUCKET');
  15. $name = 'testnotification';
  16. $prefix = 'test1';
  17. $suffix = 'mp3';
  18. $event = array("move","copy");
  19. $callbackURL = 'http://www.qiniu.com'; // 回调服务器地址,需要可以公网访问,并能够相应 200 OK
  20. list($ret, $err) = $bucketManager->putBucketEvent($bucket, $name, $prefix, $suffix, $event, $callbackURL);
  21. if ($err != null) {
  22. var_dump($err);
  23. } else {
  24. var_dump($ret);
  25. }