sopamo / laravel-filepond
Laravel 文件上传后端模块
v1.4.0
2024-04-30 10:12 UTC
Requires
- php: ^7.0|^8.0
- illuminate/contracts: 5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/http: 5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/routing: 5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: 5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^7.5|^8.0|^9.0
- phpunit/phpunit: ^9.5|^10.5
This package is auto-updated.
Last update: 2024-08-30 10:56:37 UTC
README
Laravel FilePond 后端
适用于 FilePond 的集成式 Laravel 后端
注意
如果您使用 Laravel 与 Vue.js,请查看我们另一个刚刚进入 alpha 阶段的包
🚀 2 分钟内启动
Laravel 配置
在您的 Laravel 项目的 composer.json
中添加此包。
composer require sopamo/laravel-filepond
如果您需要编辑配置,可以使用以下命令发布它
php artisan vendor:publish --provider="Sopamo\LaravelFilepond\LaravelFilepondServiceProvider"
// Get the temporary path using the serverId returned by the upload function in `FilepondController.php` $filepond = app(\Sopamo\LaravelFilepond\Filepond::class); $disk = config('filepond.temporary_files_disk'); $path = $filepond->getPathFromServerId($serverId); $fullpath = Storage::disk($disk)->get($filePath); // Move the file from the temporary path to the final location $finalLocation = public_path('output.jpg'); \File::move($fullpath, $finalLocation);
外部存储
您可以使用任何 Laravel 磁盘 作为临时文件的存储。如果您为临时文件和最终位置使用不同的磁盘,则需要将文件从临时位置复制到新磁盘,然后自行删除临时文件。
如果您使用默认的 local
磁盘,请确保您的项目中存在 /storage/app/filepond 目录,并且可写。
FilePond 客户端配置
这是在安装 laravel-filepond 之后需要设置的 FilePond JS 配置的最小值。
FilePond.setOptions({ server: { url: '/filepond/api', process: { url: "/process", headers: (file: File) => { // Send the original file name which will be used for chunked uploads return { "Upload-Name": file.name, "X-CSRF-TOKEN": "{{ csrf_token() }}", } }, }, revert: '/process', patch: "?patch=", headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' } } });
包开发
请确保在提交 PR 之前所有测试都运行成功。
测试
- 使用以下命令启动 docker 容器以执行测试:
docker run -it -v $PWD:/app composer /bin/bash
- 运行
composer install
- 运行
./vendor/bin/phpunit