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

Not able to see the preview of the image in filepond

发布于 2020-03-27 10:25:41

I am trying to use filepond to upload some images. The upload works properly. I also would like to see the preview of the images on upload. I have tried to use the plugin but apparently, I see no change.

{% block style %}
<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.min.css" rel="stylesheet">
 {% endblock %}

The below are my scripts

{% block scripts %}
</script>
<!-- FILE POND STUFF -->
<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>
FilePond.parse(document.body);
</script>
{% endblock %}

This is my JS file

$('#file_upload').change(function() {
    const inputElement = document.querySelector('input[type="file"]');

    FilePond.registerPlugin(FilePondPluginImagePreview);

    const pond = FilePond.create( inputElement, {
    allowMultiple: true,
    allowFileEncode: true,
  });

}

My HTML code

<input type="file" name='file' class='filepond' multiple  id='file_upload'/>

I am not able to figure out if there are any additional steps to this.

Questioner
Harshita
Viewed
21
Olesia 2019-07-09 16:07

If it's not too late here is a working demo https://jsfiddle.net/yza54qp0/1/

const inputElement = document.querySelector('#file_upload');

FilePond.registerPlugin(FilePondPluginImagePreview);

  const pond = FilePond.create( inputElement, {
    allowMultiple: true,
    allowFileEncode: true,
});
<link href="https://unpkg.com/filepond-plugin-image-preview@4.2.1/dist/filepond-plugin-image-preview.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/filepond@4.4.10/dist/filepond.css" rel="stylesheet"/>
<script src="https://unpkg.com/filepond-plugin-image-preview@4.2.1/dist/filepond-plugin-image-preview.js"></script>
<script src="https://unpkg.com/filepond@4.4.10/dist/filepond.js"></script>

<input type="file" name='file' class='filepond' multiple  id='file_upload'/>

<script>
FilePond.parse(document.body);
</script>