use RingCentral\Psr7\Response;
use OSS\OssClient;
use OSS\Core\OssException;
function handler($request, $context): Response
{
$credentials = $context['credentials'];
$resbody['oss']['list'] = getObjectList($credentials);
return new Response(
200,
[
'X-Powered-By' => 'nginx/1.28.0',
'Content-Type' => 'application/json',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Headers' => 'origin,accept,content-type',
],
json_encode($resbody,JSON_UNESCAPED_UNICODE)
);
}
function getObjectList($credentials){
$accessKeyId = $credentials['accessKeyId'];
$accessKeySecret = $credentials['accessKeySecret'];
$securityToken = $credentials['securityToken'];
$endpoint = 'http://oss-cn-chengdu.aliyuncs.com';
$bucket = 'bucket';
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, $securityToken);
$options = array(
'delimiter' => '/',
'prefix' => "folder",
'max-keys' => 100,
'marker' => '',
);
$listObjectInfo = $ossClient->listObjects($bucket, $options);
foreach ($listObject as $objectInfo) {
// TODO
}
return $listObject;
}