我想實現文件上傳到亞馬遜s3。我發現了以下錯誤AWS S3文件上傳使用cakephp 3
Cannot redeclare GuzzleHttp\uri_template() (previously declared in /var/www/html/appname/vendor/guzzlehttp/guzzle/src/functions.php:17) File /var/www/html/appname/vendor/aws/GuzzleHttp/functions.php
在上傳控制器,使用以下代碼來上傳
require_once("../vendor/aws/aws-autoloader.php");
use Aws\S3\S3Client;
public function upload(){
$s3 = S3Client::factory(array( 'version' =>
'latest', 'region' => 'ap-south-1', 'credentials' => array(
'key' => 'key',
'secret' => 'secret' )));
if ($this->request->is('post'))
{
if(!empty($this->request->data['file']['name']))
{
$fileName = $this->request->data['file']['name'];
$s3->putObject([
'Bucket' => backetname,
'Key' => $fileName,
'SourceFile' => $this->request->data['file']['tmp_name'],
'ContentType' => 'image/jpeg',
'ACL' => 'public-read',
'StorageClass' => 'REDUCED_REDUNDANCY'
]);
}
}
}
你的HTTP客戶端是相互矛盾的,試試這個插件https://github.com/mikesmullin/CakePHP-AWS-S3-Plugin –
是啊你是對的迪利普,HTTP客戶端是相互矛盾的。如何解決這個衝突。 – Ashok
謝謝,現在試試 – Ashok