Yii2 widget allows to integrate AWS S3 file upload. Based on File Input.
The preferred way to install this extension is through composer.
Either run
php composer.phar require andreyv/yii2-aws-file-input-widget "^1.0"
or add
"andreyv/yii2-aws-file-input-widget": "^1.0"
to the require section of your composer.json
file.
Add the following to your config file
'components' => [
...
'aws' => [
'class' => andreyv\aws\fileinput\components\Aws::class,
'credentials' => [
'key' => 'aws-access-key',
'secret' => 'aws-secret',
],
'region' => 'aws-region',
'bucket' => 'bucket-name',
],
...
],
Use with ActiveForm
echo $form->field($model, 'image')->widget(AwsFileInput::class, [
'options' => ['accept' => 'image/*'], //acceptable files
]);
echo $form->field($model, 'image')->widget(AwsFileInput::class, [
'awsComponent' => 'awsComponentName', //custom component name, `aws` by default
'uniqueKey' => 'uniqueKey', //model unique attribute, `id` by default
'options' => ['accept' => 'image/*'], //acceptable files
]);
echo $form->field($model, 'image')->widget(AwsFileInput::class, [
'awsComponent' => 'awsComponentName', //custom component name, `aws` by default
'fileNameParts' => [$model->someAttribute, 'some-key'], //custom file name parts, if not set `uniqueKey` will be used
'options' => ['accept' => 'image/*'], //acceptable files
]);