Skip to content

Intercept uploaded file #791

Answered by XzAeRo
heitorprojects asked this question in Q&A
Discussion options

You must be logged in to vote
<?php echo $form->field($model, 'attachments')->widget(
    Upload::class,
    [
        'url' => ['/file/storage/upload'],
        'sortable' => true,
        'maxFileSize' => 10000000, // 10 MiB
        'maxNumberOfFiles' => 10,
    ]
) ?>

This is what appears in the _form.php file for the articles module. You see that the attachmets field has a configuration that send data to /file/storage/upload endpoint.

That endpoint is a controller using the yii2-starter-kit/yii2-file-kit actions.

So, in the file backend/modules/file/controllers/StorageController.php, in the upload action configuration parameters, you can add the on afterSave function signature.

This way, you can add watermarks or …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@heitorprojects
Comment options

Answer selected by heitorprojects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants