indielab/yii2s3

此包的最新版本(2.0.0)没有可用的许可证信息。

Yii 2 S3 组件

安装次数: 18,313

依赖: 0

建议者: 0

安全: 0

星标: 4

关注者: 4

分支: 0

公开问题: 0

类型:yii2-extension

2.0.0 2024-05-11 20:18 UTC

This package is auto-updated.

Last update: 2024-09-03 17:13:41 UTC


README

该组件允许您处理 Amazon AWS S3 存储桶以上传和查找文件。

安装

将包添加到您的 composer 文件中

composer require indielab/yii2s3

将组件添加到您的应用程序配置文件中

'components' => [
    // ...
    's3' => [
        'class' => \indielab\yii2s3\S3::class,
        'bucket' => 'mybucket',
        'key' => 'KEY',
        'secret' => 'SECRET',
        'region' => 'eu-central-1',
    ],
    // ...
]

使用方法

使用组件上传文件

Yii::$app->s3->upload('path/to/the/file.jpg');

其中 file.jpg 将用作上传文件的键。现在要获取键的 URL,请使用

$url = Yii::$app->s3->url('file.jpg');

配置上传

您还可以向上传配置方法提供更多选项

Yii::$app->s3->upload('path/to/the/file.jpg', [
    'override' => true, // whether existing file should be overriden or not
    'Key' => 'CacheControlTestFile.txt', // Define a specific name for the file instead of the source file name
    'CacheControl' => 'max-age=' . strtotime('+1 year')  // Add cache controler options
]);