Checking Whether Objects Exist
Last updated: 2024-02-04 14:25:57
Checking Whether Objects Exist
Last updated: 2024-02-04 14:25:57
Overview
This document provides sample code for quickly checking whether an object exists in a bucket.
The sample code actually calls the HEAD Object COS API and is a simplified version of the API. In addition to checking whether an object exists, HeadObject
returns object metadata. To view the SDK API that contains the full functionality of HeadObject
, see Querying Object Metadata. Feature description
This API is used to check whether an object exists in a bucket.
Method prototype
public Guzzle\Service\Resource\Model doesObjectExist(array $args = array());
Sample code
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID";
$secretKey = "SECRETKEY";
$region = "ap-beijing";
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https',
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$result = $cosClient->doesObjectExist(
'examplebucket-125000000',
'exampleobject'
);
print_r($result);
} catch (\Exception $e) {
echo($e);
}