Sopamo / laravel-filepond

Laravel backend module for filepond uploads
MIT License
204 stars 54 forks source link

React + laravel-filepond #35

Closed rifrocket closed 4 years ago

rifrocket commented 4 years ago

Hey there, I am new with react js but I am trying to control filepond on the go, I am using your package to upload files but its giving me post error 422, can you help me with this?

Sopamo commented 4 years ago

That sounds like you are missing the csrf token in your request. Have a look at the readme on how to set the csrf token.

StephenMarkToms commented 4 years ago

@rifRocket, @Sopamo is correct. Unfortunately, what's listed in the current docs is a bit different than adding the csrf via a js framework. I'm doing the same thing but in Vue so you may need to translate it a bit differently. This is how I'm successfully passing the csrf token:

<file-pond class="mt-5" name="file" ref="pond" :server="{ url: '/file-upload', process: { headers: { 'X-CSRF-TOKEN': csrfToken } } }" allowProcess="false" allowRevert="false" label-idle="Drop files here..." accepted-file-types="application/pdf" v-bind:files="myFiles" v-on:init="handleFilePondInit" />

and then in my data prop of csrfToken has the following value:

csrfToken: document.querySelector('meta[name="csrf-token"]').content

PS: in your top most laravel blade you will need to still have the csrf token set if you don't already:

<!-- CSRF Token --> <meta name="csrf-token" content="{{ csrf_token() }}">