kha333n/laravel-filepond

Laravel后端模块,用于文件pond上传

v2.0.0 2024-07-03 07:47 UTC

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