Skip to content

Latest commit

 

History

History
190 lines (146 loc) · 3.4 KB

qingstor_service_usage.md

File metadata and controls

190 lines (146 loc) · 3.4 KB

QingStor Service Usage Guide

Import the QingStor and initialize service with a config, and you are ready to use the initialized service. Service only contains one API, and it is 'listBuckets'. To use bucket related APIs, you need to initialize a bucket from service using 'Bucket' function.

use QingStor\SDK\Service\QingStor;
use QingStor\SDK\Config;

Code Snippet

Initialize the QingStor service with a configuration

$config = new Config('ACCESS_KEY_ID_EXAMPLE', 'SECRET_ACCESS_KEY_EXAMPLE')
$service = new QingStor($config);

List buckets

$res = $service->listBuckets();

// Print the response statusCode.
echo $res->statusCode;

// Print the buckets number.
echo $res->count;

//Print the buckets data.
var_dump($res->buckets);

Initialize a QingStor bucket

$bucket = $service->Bucket('test-bucket', 'pek3a')

List objects in the bucket

$res = $bucket.listObjects()

// Print the response statusCode.
echo $res->statusCode;

// Print the objects keys.
var_dump($res->keys);

Set ACL of the bucket

$res = $bucket->putACL(
    array(
        'acl' => array(
            'grantee' => array(
                'type' => 'user',
                'ID' => 'usr-xxxxxxxx'
            ),
            'permission' => 'FULL_CONTROL'
        )
    )
);

// Print the response statusCode.
echo $res->statusCode;

Put object

// Put object
$res = $bucket->putObject(
    'object_key',
    array(
        'body' => file_get_contents('/tmp/sdk_bin'),
    )
);

// Print the response statusCode.
echo $res->statusCode;

Delete object

// Delete object
$res = $bucket->deleteObject(
    'object_key'
);

// Print the response statusCode.
echo $res->statusCode;

Initialize Multipart Upload

$res = $bucket->initiateMultipartUpload(
    'object_multipart'
);

// Print the response statusCode.
echo $res->statusCode;

// Set and print the upload ID.
echo $res->{'upload_id'};

Upload Multipart

$res = $bucket->uploadMultipart(
    'object_multipart',
    array(
        'upload_id' => $upload_id,
        'part_number' => 0,
        'body' => file_get_contents('/tmp/sdk_bin_part_0'),
    )
);

// Print the response statusCode.
echo $res->statusCode;

$res = $bucket->uploadMultipart(
    'object_multipart',
    array(
        'upload_id' => $upload_id,
        'part_number' => 1,
        'body' => file_get_contents('/tmp/sdk_bin_part_1'),
    )
);

// Print the response statusCode.
echo $res->statusCode;

$res = $bucket->uploadMultipart(
    'object_multipart',
    array(
        'upload_id' => $upload_id,
        'part_number' => 2,
        'body' => file_get_contents('/tmp/sdk_bin_part_2'),
    )
);

// Print the response statusCode.
echo $res->statusCode;

Complete Multipart Upload

$res = $bucket->listMultipart(
    'object_multipart',
    array(
        'upload_id' => $upload_id
    )
);

$object_parts = json_decode($res->getBody(), true)['object_parts'];

$res = $bucket->completeMultipartUpload(
    'object_multipart',
    array(
        'upload_id' => $upload_id,
        'etag' => '"4072783b8efb99a9e5817067d68f61c6"',
        'object_parts' => $object_parts
    )
);

// Print the response statusCode.
echo $res->statusCode;

Abort Multipart Upload

$res = $bucket->abortMultipartUpload(
    'object_multipart',
    array(
    'upload_id' => $upload_id,
    )
);

// Print the response statusCode.
echo $res->statusCode;