use*_*576 4 php amazon-s3 amazon-web-services laravel-4
我正在使用S3 php sdk和larval实现这个将对象放到S3上.
try {
$s3->putObject(array(
'Bucket' => 'mybucket',
'Key' => 'abc',
'Body' => $img->encode(null, 90),
'ACL' => 'public-read',
'ContentType' => $img->mime()
));
}
catch (S3Exception $e) {
var_dump('error');
die();
}
Run Code Online (Sandbox Code Playgroud)
但上面的代码似乎没有发现错误.我设置了一个不正确的桶,我仍然得到错误:
type:Aws\S3\Exception\NoSuchBucketException, message:The specified bucket does not exist,…
Run Code Online (Sandbox Code Playgroud)
如何捕获此错误并相应地执行操作.
要捕获所有S3异常 - 请确保引用正确的命名空间:
catch (\Aws\S3\Exception\S3Exception $e) {
Run Code Online (Sandbox Code Playgroud)
要么
<?php
use Aws\S3\Exception\S3Exception;
...
catch (S3Exception $e) {
Run Code Online (Sandbox Code Playgroud)
否则,catch块将不会捕获S3库抛出的异常.
归档时间: |
|
查看次数: |
2274 次 |
最近记录: |