Search code examples
javascriptlaravelfilepond

filepond receive undefined value in hidden input


receive undefined value in hidden input

return Response::make($this->filepond->getServerIdFromPath($filePath), 200, [
            'Content-Type' => 'text/plain',
        ]);
HTTP/1.0 200 OK
Cache-Control: no-cache, private
Content-Type:  text/plain
Date:          Mon, 25 May 2020 11:01:01 GMT

eyJpdiI6Ik1wWEY0UmNSNlRJR.....==

response generated correct but in filepond hidden receive undefined

<input type="hidden" name="filepond" value="undefined">

this is my server setting

FilePond.setOptions({
    server: {
        url: 'http://localhost/gadmin/public/filepond/api',
        timeout: 7000,
        process: {
            url: '/process',
            method: 'POST',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            onload: (response) => response.key,
            onerror: (response) => response.data,
            ondata: (formData) => {
                return formData;
            }
        },
    }
});

Solution

  • The onload function is only needed if for example your server returns a JSON string and you need to select a certain property from it. In your situation the process end point returns a text/plain response with an id, this allows FilePond to automatically use the returned id as the file id. So that's why the onload function isn't needed.

    See: https://pqina.nl/filepond/docs/patterns/api/server/#process

    server returns unique location id 12345 in text/plain response