KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Not able to upload file in resource add new field #2442

Closed Rajaram Panda opened this topic on on Nov 18, 2021 - 10 comments

Rajaram Panda commented on Nov 18, 2021

Hi, I have two issues with file upload.

got that inside ajax call in fileuploer.js CSRF token is missing, I have added code manually inside it as below for it,

if (KoolReport.dashboard.security.csrf) {
      formData.append("_token",  KoolReport.dashboard.security.csrf.token;);
    
    }

But still faced issue in file upload, because there is a missing value in "saveToFolder" variable, which is the URL to save file, but there is no value in it,

Using below code to upload file and other fileds inside resource

protected function fields()
    {
        return [
            ID::create("id")
                ->showOnCreate(0),
            Text::create("name")
                ->validators([
                    RequiredFieldValidator::create()
                        ->errorMessage("Please enter name"),
                ]),
            Image::create("upload_file"),
        ];
    }

Please have a look at the above 2 issues.

**I am using koolreport and dashboard in laravel.

KoolReport commented on Nov 18, 2021

Let me forward to dev.team to investigate

KoolReport commented on Nov 18, 2021

Let try to do this inside the fileuploader.js

        if (KoolReport.dashboard.security.csrf) {
            formData.append(KoolReport.dashboard.security.csrf.name, KoolReport.dashboard.security.csrf.token);
        }

Also, please look into your public folder "koolreport_assets" and try to remove this folder so that fileuploader.js can be refreshed.

Please let me know if it works.

DVBI commented on Nov 18, 2021

Thank you for our response, Please check it with dev team, because this is not fixing the issue.

KoolReport commented on Nov 18, 2021

May be you can turn off the csrf feature in laravel temporarily to continue with development, meanwhile our dev.team will work on the issue.

DVBI commented on Nov 18, 2021

I heve already resolved csrf token by adding below code, Please check for the 2nd issue described above for "saveToFolder" in FileUploader.php(vendor/koolreport/dashboard/inputs/FileUploader.php)

if (KoolReport.dashboard.security.csrf) {
      formData.append("_token",  KoolReport.dashboard.security.csrf.token;);
    
    }
KoolReport commented on Nov 18, 2021

Oh right, you can add directly to Image field:

Image::create("upload_file")
     ->accept(["jpg","png"])
     ->saveToFolder("uploader folder path")

Here is the extra documentation for Image field

Let us know if you need further assistance.

Anjali commented on Nov 19, 2021

Can you please suggest how to handle file uploads for csv and pdf extension in resources field?

KoolReport commented on Nov 19, 2021

Well, for csv or pdf , you can just use normal Text column with FileUploader inputWidget:

Text::create("attachment")
    ->inputWidget(
        FileUploader::create()
        ->saveToFolder(...)
        ->accept(["pdf","csv"])
    )

Let us know if you need further assistance.

Anjali commented on Nov 19, 2021

Thanks its working.

KoolReport commented on Nov 19, 2021

Awesome :)

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Dashboard