You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel升级后Filepond文件输入未随Post/Put请求提交的问题求助

Laravel升级后Filepond文件输入未随Post/Put请求提交的问题求助

大家好,我最近遇到了一个困扰许久的问题,想请各位开发者朋友帮忙排查一下。

之前我在Laravel项目中基于Filepond实现了多图上传功能,整套逻辑在Laravel 11下运行完全正常。前段时间项目暂停了一阵,重启后我把所有依赖都做了更新,还把Laravel版本升级到了12。现在其他功能都没出问题,唯独表单提交时,Filepond对应的files[]字段完全没有出现在Update方法的Request对象里,这在升级前是完全正常的。

我的Filepond相关实现代码

前端HTML与JS配置

<input type="file" name="files[]" class="filepond" multiple />
<script src="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.js"></script>
<script src="https://unpkg.com/filepond-plugin-image-exif-orientation/dist/filepond-plugin-image-exif-orientation.js"></script>
<script src="https://unpkg.com/filepond-plugin-file-validate-type/dist/filepond-plugin-file-validate-type.js"></script>
<script src="https://unpkg.com/filepond/dist/filepond.js"></script>
<script>
const inputElement = document.querySelector('input[type="file"].filepond');
FilePond.registerPlugin(FilePondPluginImagePreview, FilePondPluginImageExifOrientation, FilePondPluginFileValidateType);

FilePond.create(inputElement).setOptions({
    allowMultiple: true,
    maxFiles: 3,
    acceptedFileTypes: ['image/*'],
    allowImagePreview: true,
    server: {
        process: '/upload/process',
        revert: '/upload/remove',
        load: '/upload/load/',
        remove: (source, load, error) => {
            $.ajax({
                type:'DELETE',
                url:'/upload/removelocal',
                headers: {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
                },
                data: {
                    filename: source,
                    userid: {{ auth()->user()->id }}
                },
            });
            load();
        },
        headers: {
            'X-CSRF-TOKEN': '{{ csrf_token() }}',
        },
    },
    files: [
        @foreach ($attachments as $attachment)
            {source: '{{ $attachment->filename }}', options: {type: 'local'}},
        @endforeach
    ],
});
</script>

后端Process上传处理方法(/upload/process)

这个方法目前工作正常,文件能成功上传到tmp目录:

public function process(Request $request): string
{
    $file = $request['files'][0];
    $ext = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
    $path = $file->storeAs('tmp', now()->timestamp.'-'.Str::random(20).'.'.$ext, "private");
    return $path;
}

表单提交的Update方法

在这个方法中,我打印了完整的Request内容,但始终找不到files或files[]字段:

public function update(Request $request, string $id)
{
    Log::Debug($request->all());
    dd($request);
}

问题现象补充

  1. 文件上传到tmp目录的流程完全正常,remove方法也能正确删除本地文件
  2. 页面加载时,已有的附件图片能被正确预加载显示
  3. 浏览器控制台没有任何报错信息
  4. 查看Network面板的Post/Put请求内容,只有其他表单字段,完全没有files相关数据,日志记录如下:
[2025-06-15 16:52:56] local.DEBUG: array (
  '_method' => 'PUT',
  '_token' => 'DxmXn00LeEZ7Qc1FqV6dFft8m4pkjTSvj7Y8N5un',
  'title' => 'aaa rtfgf',
  'text' => '<p>fgdfgdf</p>',
  'tag_list' => 
  array (
    0 => '11',
  ),
  'contact_list' => 
  array (
    0 => '13',
    1 => '18',
  ),
)

我甚至尝试过修改input的name属性,排除命名冲突的可能,但问题依然存在。有没有朋友遇到过类似的情况,或者能给我一些排查方向?非常感谢!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 08:59:31