I am following Cakephp's Rest API docs to implement apis.Cakephp Rest Api Docs
Please note I am using Postman Rest Client to test the apis. As a requirement I need to provide the users to update a certain product image.
When I use POST
Request to add images for the first time, I get the Image information in $this->request->params['form']
array, which also has parameters like name, type, tmp_name, error and size
.
[form] => Array
(
[barcode_image] => Array
(
[name] => sitewide%20sales.png
[type] => image/png
[tmp_name] => C:\xampp\tmp\phpFCE8.tmp
[error] => 0
[size] => 136596
)
[image] => Array
(
[name] => phone%20number.png
[type] => image/png
[tmp_name] => C:\xampp\tmp\phpFCE9.tmp
[error] => 0
[size] => 89166
)
)
This can be easily tested in Postman by setting the field type to 'File'(which then lets you upload an image).
Now, I want to let users to Update the image which they had uploaded. For Updating i am using PUT
request for which the required MIME type is x-www-form-urlencoded
, this then prevents from updating a file.
How can I test updating of image in this scenario.
Will I have to re-write the way i have implemented the API, so that Editing of the image(re-upload a new image) to be done using POST
request?
Any help will be greatly appreciated. If I am missing out any specifics, code please ask. I'll update the question accordingly.
I googling for few minutes as per as of your problem. according to my point of you need to understand what is the purpose of
PUT
&POST
.Just Look at request->is('post') Vs request->is('put')