0
在我的應用程序中,我試圖從本地目錄中上傳圖像到亞馬遜S3存儲桶,當我上傳文件時,錯誤。我不知道要更改什麼。是否有任何更改或添加供應商?請幫忙。方法Aws S3 S3Client :: putObject()不存在
控制器:
$s = new Storage();
$result = $s->upload($bucket,$keyname,$filepath);
型號\ Storage.php:
<?php
namespace app\models;
use Yii;
use yii\base\Model;
class Storage extends Model
{
private $aws;
private $s3;
function __construct() {
$this->aws = Yii::$app->awssdk->getAwsSdk();
$this->s3 = $this->aws->createS3();
}
public function upload($bucket,$keyname,$filepath) {
$result = $this->s3->putObject(array(
'Bucket' => $bucket,
'Key' => $keyname,
'SourceFile' => $filepath,
'ContentType' => 'text/plain',
'ACL' => 'public-read',
'StorageClass' => 'REDUCED_REDUNDANCY',
'Metadata' => array(
'param1' => 'value 1',
'param2' => 'value 2'
)
));
return $result;
}
下面的錯誤是:
An Error occurred while handling another error:
exception 'ReflectionException' with message 'Method Aws\S3\S3Client::putObject() does not exist' in D:\xampp\htdocs\teespring-testmailer\vendor\yiisoft\yii2\web\ErrorHandler.php:195
嘗試調用'PutObject'而不是'putObject'。 – SiZE
沒有出現同樣的錯誤@SiZE – lalithkumar
您的供應商和方法中是否有此類「Aws \ S3 \ S3Client」?你使用什麼版本的庫? – SiZE