php 腾讯云 对象存储V5版本 获取返回的上传文件的链接方法
腾讯云 对象存储V5版本 文档地址:https://github.com/tencentyun/cos-php-sdk-v5
调用简单文件上传方法:
返回数据如下
Array ( [data:protected] => Array ( [Expiration] => [ETag] => "ed076287532e86365e841e92bfc50d8c" [ServerSideEncryption] => AES256 [VersionId] => [SSECustomerAlgorithm] => [SSECustomerKeyMD5] => [SSEKMSKeyId] => [RequestCharged] => [RequestId] => NWE3Yzg0M2NfOTcyMjViNjRfYTE1YV8xNTQzYTY= [ObjectURL] => http://testbucket-1252448703.cos.cn-south.myqcloud.com/11%2F%2F32%2F%2F43 ) )
获取返回数据中 ObjectURL 参数的值得方法如下
上传本地文件 #putObject try { $result = $cosClient->putObject(array( //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 'Bucket' => 'testbucket-125000000', 'Key' => 'string', 'Body' => fopen('./hello.txt', 'rb'), 'CacheControl' => 'string', 'ContentDisposition' => 'string', 'ContentEncoding' => 'string', 'ContentLanguage' => 'string', 'ContentLength' => integer, 'ContentType' => 'string', 'Expires' => 'mixed type: string (date format)|int (unix timestamp)|\DateTime', 'GrantFullControl' => 'string', 'GrantRead' => 'string', 'GrantWrite' => 'string', 'Metadata' => array( 'string' => 'string', ), 'StorageClass' => 'string', )); print_r($result); print_r(urldecode($result->get('ObjectURL'))); } catch (\Exception $e) { echo "$e\n"; }
获取返回的url链接的代码为:
print_r(urldecode($result->get('ObjectURL')));
如若使用的是文件流方式上传,获取返回的url链接代码为:print_r(urldecode($result->get('Location')));