Single task responses
Tasks and their responses
The response pattern in short:
- index request (GET) will return with an array of object resources
- view request (GET with ID) will return with the object resource
- update request (PUT/PATCH) will return with the object resource
- create request (POST) will return with the object resource
- exists request (HEAD) will return nothing, just 200 status code
- delete request (DELETE) will return nothing, just 204 status code
Some Shardimage function has different API endpoints as well, for more information please read our documentation here »
Examples
Upload single image
use shardimage\shardimagephp\auth\Client;
use shardimage\shardimagephp\models\image\Image;
$client = new Client([
'apiKey' => <apiKey>,
'apiSecret' => <apiSecret>,
'imageSecret' => <imageSecret>,
'cloudId' => <cloudId>,
$file = __DIR__ . '/test_image.jpg';
try {
$result = $client->getUploadService()->upload([
'file' => $file,
'tags' => ['test', 'single'],
]);
} catch (\Exception $e) {
// Handle error
}
if ($result instanceof Image) {
// Upload succeed
}
// Yii2 config file:
[
'components' => [
// ...
'shardimage' => [
'class' => \shardimage\yii2shardimage\Component::class,
'apiKey' => <apiKey>,
'apiSecret' => <apiSecret>,
'imageSecret' => <imageSecret>,
'cloudId' => <cloudId>,
],
// ...
],
]
// Component usage:
use Yii;
use shardimage\shardimagephp\models\image\Image;
$uploadService = Yii::$app->shardimage->upload();
$file = __DIR__ . '/test_image.jpg';
try {
$result = $uploadService->upload([
'file' => $file,
'tags' => ['test', 'single'],
]);
} catch (\Exception $e) {
// Handle error
}
if ($result instanceof Image) {
// Upload succeed
}
Delete single image
use shardimage\shardimagephp\auth\Client;
use shardimage\shardimagephp\models\image\Image;
$client = new Client([
'apiKey' => <apiKey>,
'apiSecret' => <apiSecret>,
'imageSecret' => <imageSecret>,
'cloudId' => <cloudId>,
try {
$result = $client->getImageService()->delete([
'publicId' => '<publicId>',
]);
} catch (\Exception $e) {
// Handle error
echo $ex->getMessage() . "\n";
}
echo "OK";
// Yii2 config file:
[
'components' => [
// ...
'shardimage' => [
'class' => \shardimage\yii2shardimage\Component::class,
'apiKey' => <apiKey>,
'apiSecret' => <apiSecret>,
'imageSecret' => <imageSecret>,
'cloudId' => <cloudId>,
],
// ...
],
]
// Component usage:
use Yii;
$imageService = Yii::$app->shardimage->image();
try {
$result = $imageService->delete([
'publicId' => '<publicId>',
]);
} catch (\Exception $e) {
// Handle error
echo $ex->getMessage() . "\n";
}
echo "OK";