在这里和那里搜索了很多之后,我将把我的问题放在这里。如果有人能在这方面提供帮助。让我来解释一下我在Laravel和Filepond上所做的事情。Filepond上传和恢复工作完美,但如果验证失败,我将面临恢复文件的问题。
files: [{
source: 'filename',
options: {
type: 'limbo',
},
}, ],
源代码来自laravel控制器函数
FilePond.setOptions({
server: {
process: './filepond-upload',
revert: './filepond-delete',
restore: './filepond-restore',
// restore: {
// url :'./filepond-restore/?id=',
// method :'GET',
// },
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Access-Control-Expose-Headers': 'Content-Disposition,'
// 'Access-Control-Expose-Headers': 'Content-Disposition',
}
}
});
控制器功能-
public function filepondRestore(Request $request, string $id) {
$abc = ('/posts/tmp/post6399a6ba2ea280.18814893/presentation_1.png');
return response()->json('', 200, [
'Content-Type' => 'image/png',
'Content-Disposition' => 'inline;
filename="'.$abc.'"',
]);
}
但是得到302重定向或500服务器错误。如果有人实现了这样的功能,我会感谢分享。提前感谢。快乐编码
感觉很粗糙,但也许有人可以帮助我们改进。
在叶片
const pond = FilePond.create(inputElement, {
acceptedFileTypes: ['video/mp4'],
@if ($errors->isNotEmpty())
files: [{
source: '{{ old('file') }}',
options: {
type: 'limbo',
}
}],
@endif
server: {
url: '/upload',
patch: "/",
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
},
},
chunkUploads: true,
chunkSize: 1048576,
chunkForce: true,
});
在控制器的索引方法中
public function index(Request $request)
{
$fileName = Storage::disk('local')->files('tmp/' . $request->restore)[0];
$fileName = explode('/', $fileName);
$nbArray = count($fileName);
$fileName = $fileName[$nbArray - 1];
$filePath = Storage::path(
Storage::disk('local')->files('tmp/' . $request->restore)[0]
);
$shortFilePath = Str::after($filePath, 'storage/app/');
$fileContents = Storage::disk('local')->get($shortFilePath);
$response = Response::make($fileContents, 200);
$response->header('Content-Disposition', 'inline; filename="' . $fileName . '"');
$response->header('Content-Type', 'video/mp4');
return $response;
}
我尝试了request->load,但没有成功,无效请求后,文件池正方形保持灰色。但是如果我使用limbo并请求->restore,它就可以工作了。
让我知道它是否有帮助,如果你有更好的解决方案。