Alibaba Cloud provides the V2 version of the SDK based on the namespace, but the documentation is not very complete and the usage threshold is relatively high, so I packaged a Composer package: https://github.com/johnlui/AliyunOSS
Installation
Add the following content to composer.json:
"johnlui/aliyun-oss": "dev-master"
}
Then run composer update
Use
//Construct OSSClient object
// Three parameters: server address, AccessKeyId provided by Alibaba Cloud, AccessKeySecret
$oss = AliyunOSS::boot('http://oss-cn-qingdao.aliyuncs.com', $AccessKeyId, $AccessKeySecret);
// Set Bucket
$oss = $oss->setBucket($bucketName);
// Upload a file (the example file is robots.txt in the public directory)
//Two parameters: resource name, file path
$oss->uploadFile('robots.txt', public_path('robots.txt'));
// Get the URL of this resource from the server and print it
// Two parameters: resource name, expiration time
echo $oss->getUrl('robots.txt', new DateTime("+1 day"));
It’s that simple. If you like it, you can star it on Github!