ItGo.me Focus on IT Recommend

Home > php - cakephp rest api multiple file uploading

php - cakephp rest api multiple file uploading

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1073

2020阿里云最低价产品入口,含代金券(新老用户有优惠),
入口地址https://www.aliyun.com/minisite/goods

up vote 0 down vote favorite I trying to upload multiple filesby REST API in cakephp V2.3. I am running api by postman addon of chrome. The issue is the format of array of files. Below is the format I am getting. It is hard to get data from the above array. Please guide me how set key to get value in standard format. Array

(

[Reports] => Array

(

[name] => Array

(

[0] => Chrysanthemum.jpg

[1] => Jellyfish.jpg

)

[type] => Array

(

[0] => image/jpeg

[1] => image/jpeg

)

[tmp_name] => Array

(

[0] => /tmp/phpDZoRzW

[1] => /tmp/phpVyb98b

)

[error] => Array

(

[0] => 0

[1] => 0

)

[size] => Array

(

[0] => 879394

[1] => 775702

)

)

)

php rest cakephp cakephp-2.3
  |
  this question edited Apr 7 '16 at 10:59 asked Apr 7 '16 at 10:53 Kapil Sharma 175 4 13 Do you want to fetch this data ? your question and question details looking difference. –  Alimon Karim Apr 7 '16 at 11:30 no, I am trying to insert data. but when getting data it is in this format –  Kapil Sharma Apr 7 '16 at 11:34



 |  1 Answers

up vote 1 down vote ---Accepted---Accepted---Accepted---

I am not entirely sure I got your question right but I think one problem lies in the data format. I assume you are using the savemany method. The data is expected in this format: $data = array(

array('name' => 'Chrysanthemum.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/tmp/phpDZoRzW', 'error' => 0, 'size' => 879394),

array('name' => 'Jellyfish.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/tmp/phpVyb98b', 'error' => 0, 'size' => 775702)

);

Basically you are providing the data field by field instead of record by record. I don't thi

Recommend:CakePHP REST API documentation

for users. For REST i think I have to provide URLs and parameters. What is the best way to prepare it Thanks! api rest cakephp documentation
  |
  this question asked Sep 16 '09 at 21:57 xpepermint 10.5k 24 93 145



nk that cake can process this correctly. To get data in the desired format you can either loop through the data or use the convenience method Hash that cakephp provides, e.g. by using extract on the required keys/values. Receive the data in the right format If you are able to change the submit-form you name the file input fields like this. The result should be the desired format. <input type="file" name="Report.0">

<input type="file" name="Report.1">

This will result in the format:

[Reports] => Array

(

[0] => Array

(

[name] => 'Chrysanthemum.jpg'

[type] => 'image/jpeg'

)

[1] => Array

(

[name] => 'Jellyfish.jpg'

[type] => 'image/jpeg'

)

)

You should use MODELNAME.{n}.FIELDNAME as naming for form fields in Cakephp, though. So if reports is your model it would make sense having a field name for your file-field.
  |
  this answer edited Apr 7 '16 at 16:21 answered Apr 7 '16 at 12:33 Gegenwind 397 4 10 yes, I want data in the format you explained. I am trying to send files in the following keys Report[0],Report[1] and so on. To get the explained format what I need to change in my key –  Kapil Sharma Apr 7 '16 at 12:42 Hi Kapil, I extended my answer, covering this aspect as well. You will find more information in the documentation about naming form fields for savemany-tasks: book.cakephp.org/2.0/en/core-libraries/helpers/form.html –  Gegenwind Apr 7 '16 at 16:25 Thanks work like a charm. –  Kapil Sharma Apr 7 '16 at 16:46



 | 

Recommend:php - REST api with CakePHP

is sent to /users.json. After the user is created, the client will be redirected to the page with the JSON representation of the user. The code I have for the controller is: class UsersController extends AppController { public $compone

up vote 0 down vote favorite I trying to upload multiple filesby REST API in cakephp V2.3. I am running api by postman addon of chrome. The issue is the format of array of files. B

------splitte line----------------------------