Skip to content

Commit d47c508

Browse files
committed
add batch operation examples
add prefetch examples
1 parent 76a1e40 commit d47c508

File tree

8 files changed

+241
-0
lines changed

8 files changed

+241
-0
lines changed

examples/rs_batch_change_mime.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keyMimePairs = array(
17+
'qiniu.mp4' => 'video/x-mp4',
18+
'qiniu.png' => 'image/x-png',
19+
'qiniu.jpg' => 'image/x-jpg'
20+
);
21+
22+
$ops = $bucketManager->buildBatchChangeMime($bucket, $keyMimePairs);
23+
list($ret, $err) = $bucketManager->batch($ops);
24+
if ($err) {
25+
print_r($err);
26+
} else {
27+
print_r($ret);
28+
}

examples/rs_batch_change_type.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$keyTypePairs = array();
23+
//type=0表示普通存储,type=1表示低频存储
24+
foreach ($keys as $key) {
25+
$keyTypePairs[$key] = 1;
26+
}
27+
28+
$ops = $bucketManager->buildBatchChangeType($bucket, $keyTypePairs);
29+
list($ret, $err) = $bucketManager->batch($ops);
30+
if ($err) {
31+
print_r($err);
32+
} else {
33+
print_r($ret);
34+
}

examples/rs_batch_copy.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$keyPairs = array();
23+
foreach ($keys as $key) {
24+
$keyPairs[$key] = $key . "_copy";
25+
}
26+
27+
$srcBucket = $bucket;
28+
$destBucket = $bucket;
29+
30+
$ops = $bucketManager->buildBatchCopy($srcBucket, $keyPairs, $destBucket, true);
31+
list($ret, $err) = $bucketManager->batch($ops);
32+
if ($err) {
33+
print_r($err);
34+
} else {
35+
print_r($ret);
36+
}

examples/rs_batch_delete.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$ops = $bucketManager->buildBatchDelete($bucket, $keys);
23+
list($ret, $err) = $bucketManager->batch($ops);
24+
if ($err) {
25+
print_r($err);
26+
} else {
27+
print_r($ret);
28+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$keyDayPairs = array();
23+
//day=0表示永久存储
24+
foreach ($keys as $key) {
25+
$keyDayPairs[$key] = 0;
26+
}
27+
28+
$ops = $bucketManager->buildBatchDeleteAfterDays($bucket, $keyDayPairs);
29+
list($ret, $err) = $bucketManager->batch($ops);
30+
if ($err) {
31+
print_r($err);
32+
} else {
33+
print_r($ret);
34+
}

examples/rs_batch_move.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$keyPairs = array();
23+
foreach ($keys as $key) {
24+
$keyPairs[$key . "_copy"] = $key . "_move";
25+
}
26+
27+
$srcBucket = $bucket;
28+
$destBucket = $bucket;
29+
30+
$ops = $bucketManager->buildBatchMove($srcBucket, $keyPairs, $destBucket, true);
31+
list($ret, $err) = $bucketManager->batch($ops);
32+
if ($err) {
33+
print_r($err);
34+
} else {
35+
print_r($ret);
36+
}

examples/rs_batch_stat.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
15+
//每次最多不能超过1000个
16+
$keys = array(
17+
'qiniu.mp4',
18+
'qiniu.png',
19+
'qiniu.jpg'
20+
);
21+
22+
$ops = $bucketManager->buildBatchStat($bucket, $keys);
23+
list($ret, $err) = $bucketManager->batch($ops);
24+
if ($err) {
25+
print_r($err);
26+
} else {
27+
print_r($ret);
28+
}

examples/rs_prefetch.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use \Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
$bucket = getenv('QINIU_TEST_BUCKET');
9+
10+
$key = "qiniu.mp4";
11+
$auth = new Auth($accessKey, $secretKey);
12+
$config = new \Qiniu\Config();
13+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
14+
$err = $bucketManager->prefetch($bucket, $key);
15+
if ($err) {
16+
print_r($err);
17+
}

0 commit comments

Comments
 (0)