Hey there! This is somewhat of an obscure one. I’m relatively certain this is the actual issue I’m facing.
I have a route which accepts POST requests containing multipart/formdata. This request can contain multiple files. When posting with a single file, I’m able to grab the request data via $kirby->request()->data() with no issues. However, once the request contains multiple files, data() is empty.
Here is a very messy route handler which produces the error.
I’ve tried commenting varying things out, and the issue occurs with multiple files even I remove everything but the line declaring $data and a simple reference to a key, like $data['name']. However, with a single file it’s fine.
However, when there are multiple files, $uploads is null. The recipe you linked is indeed what I based my implementation off of. The big difference, and what I have a feeling is the root of the error, is that I’m constructed the FormData with javascript on the frontend with multiple <input type="file" … elements.
I can see in the request I send to the Kirby route that there are indeed two File blobs contained in the FormData, both with the key file[], which is what I’d anticipate to be correct, although it does seem this is the issue. Perhaps I’ve been staring at this for too long to see the obvious solution!
Agreed. It’s the difference between selecting multiple files within a single <input> vs appending multiple files to FormData with a common key. That said, it’d be helpful to know what structure Kirby is expecting when sending multiple Files. From what I understand my way of constructing the FormData matches what the front-end looks like in the recipe you linked to.
I realize this falls outside of the immediate tooling around Kirby, so if it’s beyond the scope of support it’s fine.
With a single file it is fine, however when there are two files selected no data is contained in $uploads or $data. That is to say, the error is identically reproducible.
If the array you build looks different, which I guess it does, then you can either modify the array you send or modify the handling code to match your array structure.
That looks good, but for whatever reason, when submitting via xmlhttprequest Kirby’s response parsing breaks, only when multiple uploads are present. My post request is correctly formatted, and I can verify this by dumping the output of the raw $_REQUEST and $_FILES objects. I’m just going to roll my own solution off of that. Anyway, thanks for helping me look into this!
Wow—thought I’d update this quickly. It appears one of the images I was testing with was malformed in some way. I don’t quite understand why or how it was breaking, but when using different images, it’s fine. Totally bizarre.