简体   繁体   English

使用 vue.js 验证 laravel 中的文件

[英]validate files in laravel using vue.js

I'm trying to upload files and validate files in laravel and vue.js that uses dropzone/vue library, the file has various mimetypes such as doc, docx, xls, xlsx, ppt, jpg, jpeg, ptx, gif, png, txt, Here is my code snippet for laravel.我正在尝试上传文件并验证使用 dropzone/vue 库的 laravel 和 vue.js 中的文件,该文件具有各种 mimetypes,例如 doc、docx、xls、xlsx、ppt、jpg、jpeg、ptx、gif、png, txt,这是我的 Laravel 代码片段。 The code seems to look good but still I couldnot validate jpg and jpeg mime types.代码看起来不错,但我仍然无法验证 jpg 和 jpeg mime 类型。 and I would like to know how to pass the error to the vue component我想知道如何将错误传递给 vue 组件

public function postFileUpload(Request $request)
    {
        $validator = Validator::make($request->all(),
            ['file' => 'required|mimes:png,gif,pdf,jpg,jpeg,txt|max:8192']
        );
        if ($validator->fails()) {
            echo 'in';
            exit();
//            return redirect()->back()->withErrors($validator->errors());
//            return redirect()->back()->withErrors($validator)->withInput()->withError('please select file type');
        } else {

            echo 'out';
            exit();
        }
    }

Consider using vee-validate instead: http://vee-validate.logaretm.com/validation.html#rule-ext to validate the file on the client-side考虑使用 vee-validate: http : //vee-validate.logaretm.com/validation.html#rule-ext在客户端验证文件

v-validate.reject="'required|ext:png,gif,pdf,jpg,jpeg,txt|size:8192'" v-validate.reject="'required|ext:png,gif,pdf,jpg,jpeg,txt|size:8192'"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM