I have a big issue with receiving data from multipart form request sent by my reactJS front-end to the PHP api handled with Klein. I just tried to send with Javascript this fetch request
const data = new FormData();
data.append('sourceId', sourceId);
data.append('customerId', customerId);
const resp = await fetch(URL_CREATE_DOC, {
method: 'POST',
body: data,
headers: {
'Content-Type': 'multipart/form-data; boundary=stackoverflowrocks',
}
and then to receive in my PHP Api with this
var_dump($request->files()->all());
but there's no data ! In the header, I see that the data is well sent by the front and when I make a var_dump($request->server()), I see the CONTENT_LENGHT changing if I send files. I think I don't do something well but how can I get the data from the multipart request ?
According to the readme:
$request->
id($hash = true) // Get a unique ID for the request
paramsGet() // Return the GET parameter collection
paramsPost() // Return the POST parameter collection
paramsNamed() // Return the named parameter collection
cookies() // Return the cookies collection
server() // Return the server collection
headers() // Return the headers collection
files() // Return the files collection
body() // Get the request body
params() // Return all parameters
params($mask = null) // Return all parameters that match the mask array - extract() friendly
param($key, $default = null) // Get a request parameter (get, post, named)
files() is exclusively for uploaded files, which you don't seem to have; your values can be found in POST data, which means any one of paramsPost(), params() or param($name) would be correct.