如何删除服务器上的文件?FilePond.revert 不将参数传递给 laravel 控制器

Юри*_*нин 5 javascript php laravel filepond

FilePond.revert 不会将唯一的 id 文件传输到 laravel 控制器。

如何根据ID删除下载的文件?

文件池JS

var csrf = $('meta[name="csrf-token"]').attr('content'); 

    FilePond.setOptions({
        server: {
            url: '/file/upload/',
            process: {
                url: 'process',
                headers: {
                    'X-CSRF-TOKEN': csrf
                },
                onload: function (responce) {
                    console.log(JSON.parse(responce))
                },
            },
            revert: {
                url: 'revert',
                headers: {
                    'X-CSRF-TOKEN': csrf
                },
                onload: function (x) {

                    // X - empty, why????
                    console.log(x)

                },
            },
            load: {
                url: 'load/',
            },
        },
    })

    FilePond.create(document.querySelector('.filepond[type="file"]'), {
        files: [
            {
                source: '11',
                options: {
                    type: 'local',
                }
            },
        ]
    });
Run Code Online (Sandbox Code Playgroud)

加载图片工作成功。返回唯一 ID 文件作为响应。

public function process(){

        $file = FilesUploadService::save();

        return response($file->collection->id, 200)
            ->header('Content-Type', 'text/plain');
    }
Run Code Online (Sandbox Code Playgroud)

这里是空的,我找不到文件ID。哪些需要删除

public function revert(Request $request){
        return response()->json($request->all());
    }
Run Code Online (Sandbox Code Playgroud)

Man*_*eet 8

还在挣扎的人:

request->getContent() 将返回 filepond 发送的请求负载。

在控制器中的恢复方法中:

public function revert(Request $request){
     $fileId = request()->getContent();
     //use $fileId to delete file from filesystem
}
Run Code Online (Sandbox Code Playgroud)


Rik*_*Rik 1

下面的方法onload应该向 FilePond 返回一个唯一的 id。因此,例如,如果在中找到唯一 id,responce.id则添加如图所示的返回行。

onload: function (responce) {
    console.log(JSON.parse(responce))
    return JSON.parse(responce).id // added
},
Run Code Online (Sandbox Code Playgroud)