Pass an array in Upload event

4 posts, 0 answers
  1. Alex
    Alex avatar
    21 posts
    Member since:
    May 2013

    Posted 24 Aug 2015 Link to this post

    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

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 26 Aug 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Alex
    Alex avatar
    21 posts
    Member since:
    May 2013

    Posted 26 Aug 2015 in reply to Dimiter Madjarov Link to this post

    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

  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 27 Aug 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready