【发布时间】:2015-11-18 09:46:22
【问题描述】:
我试图在 registerStreamWrapper 上捕获错误的密钥异常,但它并没有发生。
我的问题是在尝试验证对象是否存在时产生的,如果有人打电话帮我解决这个问题(最好的方法),那就太棒了,但这是另一个问题。回到问题。
我正在使用此代码使用 registerStreamWrapper 检查对象是否存在:
try{
$s3Client = new \Aws\S3\S3Client($sharedConfig);
$s3Client->registerStreamWrapper();
$file = 's3://'."mybucket".'/'."testpath/testpic.jpg";
if(file_exists($file)){
echo "true";
}else{
echo "false";
}
} catch (S3Exception $e) {
// Catch an S3 specific exception.
echo $e->getMessage();
} catch (AwsException $e) {
// This catches the more generic AwsException. You can grab information
// from the exception using methods of the exception object.
echo $e->getAwsRequestId() . "\n";
echo $e->getAwsErrorType() . "\n";
echo $e->getAwsErrorCode() . "\n";
}
如果我提供了错误的密钥,它只会返回 false。无论如何要验证访问密钥ID和秘密访问密钥?这会让我的生活变得如此轻松。
在这里找不到任何东西:http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html 或在这里:http://docs.aws.amazon.com/aws-sdk-php/v3/guide/
【问题讨论】:
标签: php amazon-web-services amazon-s3