I have set up Laravel 11 for an SPA which is working perfectly. I know this because I have one React app using it. I set up another app for development purposes to use Uploady for file uploads.
This is where I am hitting a wall with a 419 response. In this development app I am using the following:
function App() {
// etc ...
<Uploady
multiple={false}
autoUpload={true}
inputFieldName={'file'}
forceJsonResponse={true}
withCredentials={true}
debug={true}
destination={
{
url: 'http://localhost:8080/api/v1/uploads',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json; charset=UTF-8',
'Referrer-Policy': 'strict-origin-when-cross-origin',
'Cache-Control': 'no-cache',
'X-Requested-With': 'XMLHttpRequest',
},
params: {
hello: 'world',
}
}
}>
<div>
<UploadButton>Upload Files</UploadButton>
</div>
</Uploady>
That’s all there is to it. I have debug on, and I see the output. The error I get back is 419 and there’s the error message of token mismatch.
The endpoint on Laravel 11 isn’t protected by the web.php middleware:
Route::group(['prefix' => 'api/v1', 'namespace'=> 'Api/v1'], function($router)
{
Route::post('/uploads', function(Rquest $request)
{
Log::info($request->all());
return response()->json([
'status' => true,
'message' => 'Received the data',
], 200)
->withHeaders(['Content-Type'=>'application/json; charset=utf-8']);
});
Route::get('/posts/paginate', [PostController::class, 'paginate']);
Route::post('/register', [AuthenticateController::class, 'register'])->name('register');
Route::post('/login', [AuthenticateController::class, 'login'])->name('login');
});
The endpoint is: http://localhost:8080/api/v1/uploads
clearly. My question is what must I do with to set up the CSRF token and session?
Any suggestions at this time would be really appreciated.
I am looking for a solution that will let me upload a file presently. Later I want to use this with something else to crop and upload images.