Problem with Upload
kamalsamra opened this issue · comments
On uploading Image it give 400 bad request error
My configuration is this
<?php echo froala\froalaeditor\FroalaEditorWidget::widget([
'model' => $model,
'attribute' => 'description',
'options'=>[// html attributes
'id'=>'description'
],
'clientOptions'=>[
'toolbarInline'=> false,
'theme' =>'royal',//optional: dark, red, gray, royal
'language'=>'en_gb', // optional: ar, bs, cs, da, de, en_ca, en_gb, en_us ...
'toolbarButtons' => ['fullscreen', 'bold', 'italic', 'underline', '|', 'paragraphFormat', 'insertImage'],
'imageUploadParam'=> 'file',
'imageUploadURL'=> \yii\helpers\Url::to(['/content-management/upload/'])
],
'clientPlugins'=> ['fullscreen', 'paragraph_format', 'image']
]);; ?>
Controller action is :
public function actionUpload() {
$model = new ContentManagement();
if (Yii::$app->request->isPost) {
$model->file = UploadedFile::getInstanceByName('file');
if ($model->file) {
$model->file->saveAs(ContentManagement::getContentPathForSave() . $model->file->baseName . '.' . $model->file->extension);
}
}
// Get file link
$res = array (
'link' => ContentManagement::getContentPathForResponse() . $model->file->baseName . '.' . $model->file->extension,
);
// Response data
return json_encode($res);
} ```
thank you, the current, you can disable csrf in upload controller by syntax
public $enableCsrfValidation = false;
and next, i will find best solution.
Probably too late for this, but you can set this on the widget:
'csrfCookieParam' => Yii::$app->request->csrfParam
Here is a final example:
<?= \froala\froalaeditor\FroalaEditorWidget::widget([
'name' => 'email-body',
'id' => 'email-body',
'clientOptions' => [
# Permite identificar na toolbar os parâmetros de estilo quando um texto é
# selecionado. (Ex.: Se ele esta em negrito, irá mostrar na toolbar)
'fontFamilySelection' => true,
'fontSizeSelection' => true,
'paragraphFormatSelection' => true,
# Tradução do Froala - Não esta totalmente traduzido, mas o que esta aqui
# configurado esta em português.
'language' => 'pt_br',
# Botões que irão aparecer nos dispositivos não-mobile
'toolbarButtons' => [
'bold', 'italic', 'underline',
'|',
'fontFamily', 'fontSize', 'color',
'|',
'paragraphFormat', 'align', 'formatOL', 'formatUL',
'|',
'insertHR', 'clearFormatting',
'|',
'undo', 'redo',
'-', # Nova Linha
'insertLink', 'insertImage', 'insertVideo',
],
# Botões que deverão aparecer em telas mobile
'toolbarButtonsXS' => ['bold', 'italic', 'underline', '|', 'undo', 'redo'],
# Botões de ação rápida
'quickInsertButtons' => ['image', 'hr'],
'videoAllowedProviders' => ['youtube', 'vimeo'],
'videoInsertButtons' => ['videoBack', '|', 'videoByURL'],
'imageUploadParam' => 'file',
'imageUploadURL' => \yii\helpers\Url::to(['/site/upload/']),
],
'clientPlugins' => [
'align', 'image', 'font_family',
'font_size', 'image_manager', 'line_breaker',
'link', 'lists', 'url',
'video', 'colors', 'paragraph_format',
],
'csrfCookieParam' => Yii::$app->request->csrfParam
]); ?>
@kevinsmendes It's not work for me, I was trying to find what csfrCookieParam real do, but I can not find any reference about in the whole project. It just exist in FroalaEditorWidget.
Is it possible be disabled in the new version?
Mine is 2.7.6