Sharing pictures using filepond and vue 3

I am currently facing an issue while trying to upload an image using the filepond library. The problem I am encountering is that it returns a "419 error."

As I construct my component in Vue, I have been experimenting with the following code:

<file-pond
        name="back_dni"
        ref="pond"
        class-name="my-pond"
        label-idle="DNI trasero"
        allow-multiple="false"
        accepted-file-types="image/jpeg, image/png"
        v-on:init="handleFilePondInit"
        server="/commercial/uploadDocuments" 
    />

In my script, I have included an example that is provided in the documentation:

all import to create Filepond .....

// Create FilePond component
    const FilePond = vueFilePond(FilePondPluginImagePreview,FilePondPluginFileValidateType);

    setOptions({
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        server: {
            process: {
            url: '/commercial/uploadDocuments',
            method: 'POST',
            withCredentials: false,
            onload: (response) => response.key,
            onerror: (response) => response.data,
            ondata: (formData) => {
                formData.append('Hello', 'World');
                return formData;
            },
        },
            revert: './revert',
            restore: './restore/',
            load: './load/',
            fetch: './fetch/',
        }
    });

    export default {
        name: 'uploadDniBack',
        data: function () {
            return { 
                myFiles: [] 
            };
        },
        
        methods: {
            handleFilePondInit: function () {
                // example of instance method call on pond reference
                this.$refs.pond.getFiles();
            },
        },
        components: {
            FilePond,
        },
    };

Although I am sending headers with the token, I am unsure about whether I can send this data successfully.

Answer №1

It appears that there may be an issue with your csrf token.

The 419 Page Expired HTTP response status code is a specific error related to Laravel, indicating that the Cross-Site Request Forgery (CSRF) validation has failed on the server side. Source: https://http.dev/419#:~:text=HTTP%20response%20status%20code%20419,(CSRF)%20validation%20has%20failed.

To resolve this, try replacing

$('meta[name="csrf-token"]').attr('content')
with
document.querySelector('meta[name="csrf-token"]').content
, as this solution worked for me.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discover the ins and outs of crafting a tooltip in a spreadsheet with Java-Jsp

Seeking assistance on how to incorporate a tooltip or comment feature in a spreadsheet similar to the one found in Google Spreadsheets (right-click and insert comment). For example: ![tooltip] https://sites.google.com/a/wongsk.twbbs.org/wongsk/image2/pop ...

Utilizing Angular 10 to Transform a JSON Data into a Custom String for HTML Rendering

I have received a JSON response from my backend built using Spring Boot. The "category" field in the response can either be 1 or 2, where 1 represents Notifications and 2 represents FAQs. { "pageNumber": 0, "size": 5, "totalPages&q ...

Sending the ID of a mapped button to a component

I need help with my React mapping function that displays a series of cards, each with its own button to open up a dialog box. Right now, I'm struggling to pass the unique ID from each object to the correct dialog box. Instead, all IDs are being passed ...

The file could not be located on the server during the project build and upload process

Presently, I'm engrossed in a project involving Angular 9 and ASP Core 3. You can find the website at: Nevertheless, encountering an error when trying to access this URL: http://mag-testcpl.astromap.ir/assets/vendors/global/toastr.css The culprit ...

Applying CSS to select a different element style within a webpage

I was thinking about the possibility of linking one style to another using events like :focus or :hover in CSS alone, without the need for JavaScript. For instance, can the class "hitArea" change the background attribute of "changeArea" when it is in foc ...

The hover effect is not activated by the mouse movement event

I previously encountered an issue related to flickering with an absolute div when moving my mouse, which I managed to resolve by increasing the distance between my mouse pointer and the div. Now, I am working on the next phase of my project: My goal is t ...

Utilizing Vue to Embed Multiple Hubspot Forms on one Page

While working on a Vue page, I encountered an issue with loading multiple Hubspot forms simultaneously. Only one form would load at a time. Here is the code snippet I used to append a single Hubspot form: mounted() { const script = document.createElem ...

Slide up to 100 pixels above the anchor using jQuery

I am looking for a solution where the anchor position is 100px below the top of the page instead of jumping to the very top. I prefer not to have any animations, and I want to avoid the anchor jumping twice. I am seeking a universal fix for this issue. I ...

Error encountered while attempting to run a database query: SQLSTATE[42S22]: Column 'category_name' not found, 1054 Unknown column in 'field list' (SQL: insert into 'categorie')

Error: Illuminate\Database\QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'category_name' in 'field list' (SQL: insert into categories (category_name, updated_at, created_at) values (fruits, 2022-08-08 1 ...

How can the border of the select element be removed when it is active in select2

After examining the CSS code, I am still unable to locate the specific property that is being applied to the main element. I am currently customizing the select2 library to suit my needs. However, I am stuck in the CSS as I cannot determine which property ...

JavaScript innerHTML not functioning properly when receiving a response from a servlet

Can someone help me troubleshoot the code below? I'm receiving a response from the servlet, but I can't seem to display it inside the div. Here is the response: lukas requests to be your friend &nbsp <button value="lukas"onclick="accfr(th ...

Am I using async/await correctly in this code?

Here is the code snippet I am currently working with: var process = async (items: DCXComposite[], session: Session) => { // This function returns a response object with a statusCode property. If the status Code is 200, it indicates a ...

(Node Express) The style was not applied due to its MIME type ('text/html') not being a supported stylesheet MIME type, with strict MIME checking being enabled

My CSS styles are not applying because of a MIME type issue. I am using Express to serve my HTML page, but for some reason, the CSS is not being displayed correctly. I have tried various solutions, but it seems like I am missing something simple. Can someo ...

show.bs.modal event does not trigger within a bootstrap 4 modal that is loaded externally

I am trying to implement a feature where a common modal dialog can be loaded into any page from an external file. While the functionality works, I am facing an issue where the show.bs.modal and hide.bs.modal events are not triggered when the modal markup i ...

Utilize the $.each method to incorporate a value to an outside variable

Within my codebase, I handle an Array of Strings by utilizing the following function: $.each(lines, processLine); The challenge I faced was that while the processLine function returns a string, I needed to merge all the strings into one final result. How ...

Trouble arises when implementing personalized buttons on the Slick JS slider

Are you struggling to customize buttons for your Slick Slider JS? I am facing a similar issue with applying my own button styles to the slider. I am interested in using arrow icons instead of the default buttons. Here is the HTML code snippet: <secti ...

What is the method to deactivate the date field by using an attribute?

In an attempt to disable a field using an attribute without utilizing the directive scope property, I am seeking a way to disable my field with the type 'date'. Check out my code snippet below: http://plnkr.co/edit/eJDRocLYkr8Krh84vFKY?p=previe ...

Removing items from a list of JSON objects in Vue.js based on their index position

I am currently working on creating a list of elements, each element containing a "remove" button that is intended to delete the specific element it corresponds to. You can view the current implementation here: http://jsbin.com/jalexekeho/edit?html,js,cons ...

Rotating a specific part of a model in THREE.js

Whether it's feasible to adjust the position or rotation of a component within an OBJ (or similar format) model. Can one manipulate a single model instead of needing multiple ones? What is the optimal approach to achieve this goal effectively? Appreci ...

Utilizing AJAX to load a WAV file

One of the tasks I'm working on involves a collection of audio files. When a file from this list is clicked, I want JavaScript to load and display the waveform of that specific audio file. The following function is responsible for drawing the wavefor ...