Search code examples
filepond

I can't get image preview to work on filepond


I have done literally everything to make it work but it is not working yet

I loaded from cdn just as it is in the preview documentation

<!-- add to document <head> -->
<link href="https://unpkg.com/filepond/dist/filepond.css" 
rel="stylesheet">
<link href="https://unpkg.com/filepond-plugin-image-preview/dist/filepond- 
plugin-image-preview.css" rel="stylesheet">

<!-- add before </body> -->
<script src="https://unpkg.com/filepond-plugin-image- 
preview/dist/filepond-plugin-image-preview.js"></script>
<script src="https://unpkg.com/filepond/dist/filepond.js"></script>

To enhance into a filepond element I have

<script>
const inputElement = document.querySelector('input[type="file"]');
const pond = FilePond.create( inputElement );
</script>

and lastly

<input type="file">

It just shows up as a file and not with image preview. What am I missing?


Solution

  • The plugins have not been registered with FilePond.

    This should work:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>FilePond Plugin Image Preview Demo</title>
        <link href="https://unpkg.com/filepond/dist/filepond.css" rel="stylesheet">
        <link href="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.css" rel="stylesheet">
    </head>
    <body>
    
        <input type="file"/>
    
        <script src="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.js"></script>
        <script src="https://unpkg.com/filepond/dist/filepond.js"></script>
    
        <script>
        // Register the plugin with FilePond
        FilePond.registerPlugin(FilePondPluginImagePreview);
    
        // Get a reference to the file input element
        const inputElement = document.querySelector('input[type="file"]');
    
        // Create the FilePond instance
        const pond = FilePond.create(inputElement);
        </script>
    
    </body>
    </html>
    

    Live demo here: https://pqina.github.io/filepond-plugin-image-preview/

    I'm looking at the docs and I see how this is confusing, will improve them as soon as I have some time.