filepond README

项目的 README,来自 github.com/pqina/filepond。合并为一个 markdown 文件:README.md。

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 our 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

filepond (pqina/filepond)

正在搜索数据库…

这是什么?FilePond 是一个 JavaScript 文件上传库,支持拖放、选择文件和异步上传,并会自动优化图片(调整尺寸、裁剪、应用滤镜、修复 EXIF 方向),让上传体验更流畅、更易用。
它是独立的库,还是需要依赖某个框架?它的核心是原生 JavaScript 库,同时提供官方适配器,可用于 React、Vue、Angular、Svelte 和 jQuery 项目。
我该如何把它添加到项目中?可以用 npm 安装并在代码中导入,也可以直接通过 CDN 的 script 标签引入。
接收上传文件需要特定的后端吗?不需要特定的后端,但社区维护了现成的服务端集成方案,支持 PHP、Django、Laravel、SilverStripe 和 Ruby on Rails,用于处理上传接口。
FilePond 目前的稳定性和测试覆盖情况如何?据维护者自己说,测试覆盖率只有约 65%。如果需要支持 IE11 或其他旧版浏览器,你必须自行添加单独的 FilePond Polyfill 和 Babel polyfill。
FilePond 会自动对图片做哪些处理?在上传前,它会自动调整图片尺寸、裁剪、应用滤镜,并即时修复 EXIF 方向,因此无需额外代码,图片就能以优化后的状态上传。
上传前能编辑图片吗,比如裁剪或旋转?FilePond 本身专注于上传体验,但它可以与作者的另一个 JavaScript 图片编辑器 Pintura 集成,从而添加裁剪、旋转、调整尺寸和翻转等工具。
有哪些插件可以扩展 FilePond 的功能?官方插件包括文件编码、重命名、文件大小和类型校验、元数据、视频封面图,以及图片预览、裁剪、调整尺寸、滤镜和变换;社区还提供若干插件,如 PDF 预览和 zip 上传等。
文件究竟是如何发送到服务器的?FilePond 通过 AJAX 异步上传,支持对大文件进行分块上传,也可以将文件编码为 base64,或随普通表单提交一同发送。
作者
pqina
大小
9.5 MB
星标
16.4K
时长
9年
提交 · 90 天