AliyunOss如何判断Obeject是否存在

AliyunOss如何判断Obeject是否存在



/**

* 判断上传文件是否存在

*/

public static function buildImageIsCheck($object_id)

{

    $accessKeyId = Yii::$app->params['oss']['accessKeyId'];                //获取阿里云oss的accessKeyId

    $accessKeySecret = Yii::$app->params['oss']['accessKeySecret'];        //获取阿里云oss的accessKeySecret

    $endpoint = Yii::$app->params['oss']['endPoint'];

    $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint);;

    $file_object = md5($object_id);

    $bucket = Yii::$app->params['oss']['bucket'];

    $model =  $oss->getObjectMeta($bucket, $file_object);

    return isset($model['info']['url'])?$model['info']['url']:'';

}

你可能感兴趣的:(AliyunOss如何判断Obeject是否存在)