I'm currently trying to parse the multipart/form-data
that I send through Postman plugin in Chrome. However, I get the following output:
'------WebKitFormBoundarymsXhoqlRBbTbsZFb
Content-Disposition: form-data; name="album_id"
2
------WebKitFormBoundarymsXhoqlRBbTbsZFb
Content-Disposition: form-data; name="description"
haiahaahahahdaisdhisadhisadihsdhiiahsd
------WebKitFormBoundarymsXhoqlRBbTbsZFb
Content-Disposition: form-data; name="favorite"
true
------WebKitFormBoundarymsXhoqlRBbTbsZFb
Content-Disposition: form-data; name="uploadfile"; filename="test2.txt"
Content-Type: text/plain
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
------WebKitFormBoundarymsXhoqlRBbTbsZFb
Content-Disposition: form-data; name="uploadfile"; filename="test.txt"
Content-Type: text/plain
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
------WebKitFormBoundarymsXhoqlRBbTbsZFb--
'
This output do I get when I try to debug $this->request->input()
. When I try $this->request->input('json_decode')
I get an empty array, so I'm assuming that the data isn't in a proper format (just a string). Before I write my own algorithm I want to be sure that I'm not reinventing the wheel with this one. I'm doing something wrong? Or if not, does there exist some Cakephp 3 function which takes care of this?
Update
I found what is wrong in my code and it seems like the routing process somehow empties the post array to early. When I try Postman with the following endpoint http://vecto.app/api/pictures $this->request->data is empty. However, when I try to access the endpoint http://vecto.app/pictures the $this->request->data is filled with the information. Does anyone know what is wrong with the following routing setup:
Router::prefix('api', function ($routes) {
$routes->extensions(['json', 'xml']);
$routes->resources('Users');
$routes->resources('Pictures');
// We connect the /register action so we can simply extend the CRUD Plugin add() method
// and benefit of already available logic like validation and response codes instead of having to reinvent the wheel.
Router::connect('/api/users/register', ['controller' => 'Users', 'action' => 'add', 'prefix' => 'api']);
$routes->fallbacks('InflectedRoute');
});