kha333n / laravel-filepond
Laravel后端模块,用于文件pond上传
v2.0.0
2024-07-03 07:47 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
README
Laravel FilePond 后端
一个集成的Laravel后端,适用于FilePond
注意
如果您正在使用Laravel和Vue.js,请查看我们刚进入alpha测试阶段的另一个包
🚀 2分钟内快速启动
Laravel设置
在您的Laravel项目的composer.json中添加此包。
composer require kha333n/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