无法处理的实体:在 Laravel 中使用 filepond 异步上传文件时为 422
Unprocessable Entity: 422 while uploading file Asynchronously using filepond in Laravel
我正在使用 filepond to upload my files to the server using Laravel filepond Backend package。
但是,使用 Filepond 异步上传文件时使用 XMLHttpRequest
。我注意到控制台中弹出以下错误。
Getting 422 (unprocessable entity) Error in console.
文件: Sopamo\LaravelFilepond\Http\Controllers\FilepondController.php
public function upload(Request $request)
{
$input = $request->file(config('filepond.input_name')); // $input = null
下面是调试upload
方法中的$request
参数得到的值。
$request->files->parameters["filepond"]->test: false
$request->files->parameters["filepond"]->originalName: "originalFileName.pdf" //this is filename
$request->files->parameters["filepond"]->mimeType: "application/pdf"
$request->files->parameters["filepond"]->error: 0
$request->files->parameters["filepond"]->*SplFileInfo*pathName: "C:\xampp\tmp\php16E1.tmp"
$request->files->parameters["filepond"]->*SplFileInfo*fileName: "php16E1.tmp"
我的config\filepond.php
和Sopamo/Laravel Package config file一样。
以下是我的配置:
FilePond.registerPlugin(
FilePondPluginFileEncode
);
FilePond.create(document.querySelector('input[type="file"]'));
FilePond.setOptions({
server: {
url: '/filepond/api',
process: '/process',
revert: '/process',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
}
});
FilePond.parse(document.body);
<html lang="en">
<head>
<link href="https://unpkg.com/filepond/dist/filepond.css" rel="stylesheet">
</head>
<body>
<input type="file" name="filepond" required multiple>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script src="https://unpkg.com/filepond/dist/filepond.js"></script>
<script src="https://unpkg.com/filepond-plugin-file-validate-size/dist/filepond-plugin-file-validate-size.js"></script>
<script src="https://unpkg.com/filepond-plugin-file-encode/dist/filepond-plugin-file-encode.js"></script>
<script src="https://unpkg.com/jquery-filepond/filepond.jquery.js"></script>
</body>
</html>
文件: routes\web.php
Route::prefix('api')->group(function () {
Route::post('/process', [FilepondController::class, 'upload'])->name('filepond.upload');
Route::delete('/process', [FilepondController::class, 'delete'])->name('filepond.delete');
});
谢谢。
我通过将 file
的名称属性值添加到我的文件输入元素来解决它。从 <input type="file" name="filepond">
到 <input type="file" name="file">
.
我正在使用 filepond to upload my files to the server using Laravel filepond Backend package。
但是,使用 Filepond 异步上传文件时使用 XMLHttpRequest
。我注意到控制台中弹出以下错误。
Getting 422 (unprocessable entity) Error in console.
文件: Sopamo\LaravelFilepond\Http\Controllers\FilepondController.php
public function upload(Request $request)
{
$input = $request->file(config('filepond.input_name')); // $input = null
下面是调试upload
方法中的$request
参数得到的值。
$request->files->parameters["filepond"]->test: false
$request->files->parameters["filepond"]->originalName: "originalFileName.pdf" //this is filename
$request->files->parameters["filepond"]->mimeType: "application/pdf"
$request->files->parameters["filepond"]->error: 0
$request->files->parameters["filepond"]->*SplFileInfo*pathName: "C:\xampp\tmp\php16E1.tmp"
$request->files->parameters["filepond"]->*SplFileInfo*fileName: "php16E1.tmp"
我的config\filepond.php
和Sopamo/Laravel Package config file一样。
以下是我的配置:
FilePond.registerPlugin(
FilePondPluginFileEncode
);
FilePond.create(document.querySelector('input[type="file"]'));
FilePond.setOptions({
server: {
url: '/filepond/api',
process: '/process',
revert: '/process',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
}
});
FilePond.parse(document.body);
<html lang="en">
<head>
<link href="https://unpkg.com/filepond/dist/filepond.css" rel="stylesheet">
</head>
<body>
<input type="file" name="filepond" required multiple>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script src="https://unpkg.com/filepond/dist/filepond.js"></script>
<script src="https://unpkg.com/filepond-plugin-file-validate-size/dist/filepond-plugin-file-validate-size.js"></script>
<script src="https://unpkg.com/filepond-plugin-file-encode/dist/filepond-plugin-file-encode.js"></script>
<script src="https://unpkg.com/jquery-filepond/filepond.jquery.js"></script>
</body>
</html>
文件: routes\web.php
Route::prefix('api')->group(function () {
Route::post('/process', [FilepondController::class, 'upload'])->name('filepond.upload');
Route::delete('/process', [FilepondController::class, 'delete'])->name('filepond.delete');
});
谢谢。
我通过将 file
的名称属性值添加到我的文件输入元素来解决它。从 <input type="file" name="filepond">
到 <input type="file" name="file">
.