kartik-v / yii2-widget-fileinput

An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)
Other
229 stars 96 forks source link

Invalid thumb frame with id: #160

Closed sergmoro1 closed 4 years ago

sergmoro1 commented 4 years ago

I placed the widget in a view, write an action in controller. Everything well - I can choice a photo and preview it. But nothing had happened in console. Only message "Invalid thumb frame with id: ...". That's all. No POST with api/upload-photo or errors.

View

use kartik\file\FileInput;

    <?= $form->field($model, 'file_photo')->widget(FileInput::classname(), [
        'options' => [
            'multiple' => false,
        ],
        'pluginOptions' => [
            'uploadUrl' => Url::to(['api/upload-photo']),
            'uploadExtraData' => ['id' => $model->id],
            'allowedFileExtensions' => ["jpg", "png", "gif"],
            'autoReplace' => true,
            'showCaption' => false,
            'showRemove' => true,
            'showUpload' => false,
            'dropZoneEnabled' => false,
            'maxTotalFileCount' => 1,
            'maxFileCount' => 1,
            'validateInitialCount' => true,
            'overwriteInitial' => true,
            'layoutTemplates' => [
                'main2' => '<div class="file-preview-thumbnails"></div>',
            ],
            'previewTemplates' => [
                'image' => '<img class="avatar" src="{data}" />',
            ],
            'defaultPreviewContent' => ('<img class="avatar" src="'. $model->getPhoto() . '" />'),
        ],
    ]); ?>

Controller

public function actionUploadPhoto()
{
    if (Yii::$app->request->isAjax) {
        $id = Yii::$app->request->post('id');
        $model = UserProfile::findOne($id);
        // this will be something to save an uploaded file
        return $this->asJson([true]);
    }
}
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.