This is a migrated thread and some comments may be shown as answers.

Pass an array in Upload event

3 Answers 222 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Iron
Alex asked on 24 Aug 2015, 12:15 PM

Hi

While uploading an image I send a lot of image metadata from a form by attaching the data to e.data in the upload event.
Now I would like to add an array of keyword id's with the usual POST serialization like: keyword_id[]=143&keyword_id[]=211
but all I get is a serialization like: keyword_id[] = 143,211,....

Is there a simple hack to achieve that?

Regards

Alex

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 26 Aug 2015, 07:47 AM

Hello Alex,

In this case, the MVC model binder expects the additional data to be submitted in separate fields in the format "name[index]".
E.g.

var ids = [ ... ];
for (var i = 0; i < ids.length; i++) {
    e.data["fileUploadIds[" + i + "]"] = ids[i];
}

This way you could access the fileUploadIds collection as an additional parameter in the save handler.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Alex
Top achievements
Rank 1
Iron
answered on 26 Aug 2015, 12:05 PM

Hi Dimiter

thank you for your reply. The problem is, that I use the very same form twice in different modes. Initially I use to form to upload images with metadata. As an image can be tagged with various keywords, the keywords are sent as an array.
When I use the form to edit the metadata of an already uploaded image, I send the form data as usual POST data. Hence the keywords are sent like: like keyword_id[]=142&keyword_id[]=988....etc. and handled on the server using a PHP script. When I use the form to upload a new image asynchronously, I have to send the data as described in the previous post and I would appreciate if I could handle the request with the very same PHP script without having to fiddle around too much.

Currently I upload the image synchronously to overcome the problem but it would be nice, if an array could be serialized the traditional way using e.data in the upload event.

Regards

Alex

0
Dimiter Madjarov
Telerik team
answered on 27 Aug 2015, 08:53 AM

Hello Alex,

The current problem is not directly related to the Kendo UI Upload widget, but to the handling of the form data on the backend due to the way arrays are sent via FormData. If you are experiencing any Kendo UI specific issues, do not hesitate to contact us.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Upload
Asked by
Alex
Top achievements
Rank 1
Iron
Answers by
Dimiter Madjarov
Telerik team
Alex
Top achievements
Rank 1
Iron
Share this question
or