Warm tip: This article is reproduced from stackoverflow.com, please click
filepond javascript laravel

filepond receive undefined value in hidden input

发布于 2020-08-17 03:53:04

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;
            }
        },
    }
});
Questioner
Hik200
Viewed
36
Rik 2020-05-28 15:14

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