laravel操作s3私有云

1.通過composer require aws/aws-sdk-php 2.*安裝aws包

2.實(shí)例化一個(gè)S3客戶端

 $this->client = S3Client::factory([
            'credentials' => array(
                'key' => env('AWS_ACCESS_KEY_ID'),
                'secret'  => env('AWS_SECRET_ACCESS_KEY'),
            ),
            "region" => "region1",
            "scheme" => "http",
            "version" => "latest",
            "endpoint"=> 'http://'.env('ENDPOINT'),
        ]);

3.創(chuàng)建Bucket

 return $this->client->createBucket([
            'Bucket' => $this->install_bucket,
            'ACL' => 'public-read-write'//ACL一定要大寫要不然權(quán)限設(shè)置無效
        ]);

4.自定義文件名上傳服務(wù)器

 $this->client->putObject([
            'Bucket' => $this->install_bucket,
            'Key' => $fileName,//自定義的文件名
            'Body' => file_get_contents($file),//通過$request->input('file')接收到的二進(jìn)制文件,通過file_get_contents()直接賦值給Body
            'ACL' => 'public-read-write'  //ACL一定要大寫要不然權(quán)限設(shè)置無效
        ]);

5.更多操作詳見
https://gist.github.com/mlconnor/4540839

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容