pqina/filepond

Public

🌊 A flexible and fun JavaScript file upload library

  • Stars16.4k+5 tuần này
  • Forks852
  • Watchers157
  • Issues31
  • Ngày tạo09/10/2017
  • Cập nhật gần nhất04/12/2026
  • Ngôn ngữTypeScript
  • Giấy phépMIT
README.md13.2 KBRaw

FilePond

License: MIT npm version npm Discord

A JavaScript library that can upload anything you throw at it, optimizes images for faster uploads, and offers a great, accessible, silky smooth user experience.

Installing FilePond

Install the filepond package by running the following command in your terminal:

npm install filepond

Quick Start

Wrap an <input type="file"> with the <file-pond> custom element and then register the custom element using the defineFilePond function.

Getting started

<form action="/upload" method="POST">
    <label for="my-file">Files</label>
    <file-pond>
        <input id="my-file" type="file" name="files" required />
    </file-pond>

    <button type="submit">Upload</button>
</form>

<script type="module">
    import { defineFilePond } from 'filepond';
    import { locale } from 'filepond/locales/en-gb.js';

    const elements = defineFilePond({
        locale,
    });
</script>

Integrating FilePond With a Framework

When integrating with a framework like React, Svelte, Vue, or Angular we can use the <file-pond> custom element as if it were a Component.

Framework integration

import { useState } from 'react';

// FilePond imports
import { defineFilePond, type FilePondEntrySource, type FilePondElement } from 'filepond';
import { locale } from 'filepond/locales/en-gb.js';

// Optionally import React <file-pond> component types
import 'filepond/types/react';

// Define <file-pond> element and sets English locale
defineFilePond({
    locale,
});

export default function App() {
    // two-way data binding
    const [entries, setEntries] = useState<FilePondEntrySource[]>([
        new File(['hello'], 'world.txt', {
            type: 'text/plain',
        }),
    ]);

    // handle form submit
    function handleSubmit(e: React.SyntheticEvent<HTMLFormElement>) {
        e.preventDefault();

        console.log('submit', e);
    }

    return (
        <form onSubmit={handleSubmit} method="POST">
            <label htmlFor="my-files">Documents</label>
            <file-pond
                onentrieschange={({ detail: currentEntries }) => {
                    setEntries(currentEntries);
                }}
                entries={entries}
            >
                <input id="my-files" name="my-files" type="file" required multiple />
            </file-pond>

            <button type="submit">Sumbit</button>
        </form>
    );
}

License

MIT

Nội dung README thuộc về pqina và cộng đồng đóng góp, giấy phép MIT. Nguồn: github.com/pqina/filepond