overtrue / qcloud-cos-client Goto Github PK
View Code? Open in Web Editor NEWTencent COS Client
Tencent COS Client
$service->getBuckets();
$service->getBuckets('ap-guangzhou');
$job->getJobs(array $query = []);
$job->createJob(array $body);
$job->describeJob(string $id);
$job->updateJobPriority(string $id, int $priority);
$job->updateJobStatus(string $id, array $query);
$bucket->putBucket(array $body);
$bucket->headBucket();
$bucket->deleteBucket();
$bucket->getObjects(array $query = []);
$bucket->getObjectVersions(array $query = []);
$bucket->putVersions(array $body);
$bucket->getVersions();
$bucket->putACL(array $body, array $headers = [])
$bucket->getACL();
$bucket->putCORS(array $body);
$bucket->getCORS();
$bucket->deleteCORS();
$bucket->putLifecycle(array $body);
$bucket->getLifecycle();
$bucket->deleteLifecycle();
$bucket->putPolicy(array $body);
$bucket->getPolicy();
$bucket->deletePolicy();
$bucket->putReferer(array $body);
$bucket->getReferer();
$bucket->putTaging(array $body);
$bucket->getTaging();
$bucket->deleteTaging();
$bucket->putWebsite(array $body);
$bucket->getWebsite();
$bucket->deleteWebsite();
$bucket->putInventory(string $id, array $body)
$bucket->getInventory(string $id)
$bucket->getInventoryConfigurations(?string $nextContinuationToken = null)
$bucket->deleteInventory(string $id)
$bucket->putVersioning(array $body);
$bucket->getVersioning();
$bucket->putReplication(array $body);
$bucket->getReplication();
$bucket->deleteReplication();
$bucket->putLogging(array $body);
$bucket->getLogging();
$bucket->putAccelerate(array $body);
$bucket->getAccelerate();
$bucket->putEncryption(array $body);
$bucket->getEncryption();
$bucket->deleteEncryption();
$bucket->putObject(string $key, string $body, array $headers = []);
$bucket->copyObject(string $key, array $headers = []);
$bucket->getObject(string $key, array $query = [], array $headers = []);
$bucket->headObject(string $key, string $versionId, array $headers = []);
$bucket->restoreObject(string $key, string $versionId, array $body);
$bucket->selectObjectContents(string $key, array $body);
$bucket->deleteObject(string $key, string $versionId);
$bucket->deleteObjects(array $body);
$bucket->putObjectACL(string $key, array $body, array $headers = []);
$bucket->getObjectACL(string $key);
$bucket->putObjectTagging(string $key, string $versionId, array $body);
$bucket->getObjectTagging(string $key, string $versionId);
$bucket->deleteObjectTagging(string $key, string $versionId);
$bucket->createUploadId(string $key, array $headers = []);
$bucket->uploadPart(string $key, int $partNumber, string $uploadId, string $body, array $headers = []);
$bucket->copyPart(string $key, int $partNumber, string $uploadId, array $headers = []);
$bucket->markUploadAsCompleted(string $key, string $uploadId, array $body);
$bucket->markUploadAsAborted(string $key, string $uploadId);
$bucket->getUploadJobs(array $query = []);
$bucket->getUploadedParts(string $key, string $uploadId, array $query = []);
接口:
Overtrue\CosClient\ObjectClient -> putObjectACL()
调用方法:
$client->putObjectACL($path,[],["x-cos-acl" => "public-read"])
抛出异常
Overtrue\CosClient\Exceptions\ClientException : Client error: `PUT https://x.cos.ap-guangzhou.myqcloud.com/x.jpg?acl=` resulted in a `400 Bad Request` response:
<?xml version='1.0' encoding='utf-8' ?>
<Error>
<Code>InvalidArgument</Code>
<Message>AccessControlPolicy is not well- (truncated...)
发送的数据:
打印 Overtrue\CosClient\ObjectClient
第 95 行的第二个参数得到:
[ // vendor/overtrue/qcloud-cos-client/src/ObjectClient.php:186
"query" => array:1 [
"acl" => ""
]
"body" => "<xml/>"
"headers" => array:1 [
"x-cos-acl" => "public-read"
]
]
如果将 Overtrue\CosClient\Support\XML::fromArray(array $data):bool|string 方法重写为:
public static function fromArray(array $data): bool|string
{
if (empty($data)) return '';
return Transformer::toXml($data);
}
Overtrue\CosClient\ObjectClient
第 95 行的第二个参数得到:
[ // vendor/overtrue/qcloud-cos-client/src/ObjectClient.php:186
"query" => array:1 [
"acl" => ""
]
"body" => ""
"headers" => array:1 [
"x-cos-acl" => "public-read"
]
]
则接口调用成功
做为公共类组件,版本要求过高会导致一些限制,可否考虑一下,降到 7.1 or 7.2
when i update to new version , file uploading has exception error:
Overtrue\CosClient\Signature::getTimeSegments(): Argument #1 ($expires) must be of type DateTimeInterface|string|int, null given, called in /var/www/html/vendor/overtrue/qcloud-cos-client/src/Signature.php on line 26
as i checked $expires variable is null and when i set value for $expires to int like 10 , it will work.
When using custom domain, current signature will contain custom domain host, it will cause tencent cloud api return "403 Forbiddden".
So in Class Signature, maybe __construct should contain parameters like bucket, app_id, region, and in getHeadersToBeSigned should replace host part to prevent error, like
protected static function getHeadersToBeSigned(RequestInterface $request): array
{
$headers = [];
foreach ($request->getHeaders() as $header => $value) {
$header = strtolower(urlencode($header));
if (str_contains($header, 'x-cos-') || \in_array($header, self::SIGN_HEADERS)) {
if ($header == 'host') {
$value[0] = \sprintf(
'%s-%s.cos.%s.myqcloud.com',
$this->bucket,
$this->app_id,
$this->region
);
}
$headers[$header] = $value[0];
}
}
ksort($headers);
return $headers;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.